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());
}
}
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());
}
}