1. 程式人生 > >.分析以下需求,並用程式碼實現 1.定義List集合,存入多個字串 2.刪除集合元素字串中包含0-9數字的字串 只要字串中包含0-9中的任意一個數字就需

.分析以下需求,並用程式碼實現 1.定義List集合,存入多個字串 2.刪除集合元素字串中包含0-9數字的字串 只要字串中包含0-9中的任意一個數字就需

public class MyText2 {


public static void main(String[] args) {
/*
* 2.分析以下需求,並用程式碼實現 1.定義List集合,存入多個字串
*  2.刪除集合元素字串中包含0-9數字的字串
* (只要字串中包含0-9中的任意一個數字就需要刪除此整個字串) 
* 3.然後利用迭代器遍歷集合元素並輸出
*/
//需要一個字串集合
List<String> strList = new ArrayList<String>();
strList.add("aaa");
strList.add("ccc99");
strList.add("cccer99");
strList.add("ccccsd99");
strList.add("ccasad99");
strList.add("9cads2sa23dsa");
strList.add("ccc32csd99");
strList.add("cc1asad99");
strList.add("cad3a23dsa");
//遍歷集合中的元素
for (int i = 0; i < strList.size(); i++) {
//每個元素轉換成字元陣列
char[] ch = strList.get(i).toCharArray();
//遍歷字元陣列
for (int j = 0; j < ch.length; j++) {
//判斷是否包含
if (ch[j] >= '0' && ch[j] <= '9') {
//進行刪除
strList.remove(i);
//改變集合的索引
i--; 
break;//結束本次迴圈
}
}
}
//迭代
ListIterator<String> listString = strList.listIterator();
//遍歷輸出
while (listString.hasNext()) {
System.out.println(listString.next());
}
}