if(list.get(i).contains("[0-9]")) {这一句不知道你什么意思?
list.get(i).macths("0-9")是判断字符串中是否全为数字
下面我改了你的代码实现:
ArrayList<String> list = new ArrayList<String>();
list.add("abcd321");
list.add("ab0cde");
list.add("1ab2d3");
list.add("bcd32");
list.add("c0hdkf");
list.add("chdkf");
System.out.println(list);
deleteNum(list);
System.out.println(list);
}
public static void deleteNum(ArrayList<String> list) {
for(int i = list.size() - 1;i >= 0;i--) {
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(list.get(i).toString());
if(m.matches()){
list.remove(i);
System.out.println("11");
}
}
} |