public class ArrayListDemo {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
al.add("hello");
al.add("world");
al.add("abc");
al.add("java");
al.add("uncle");
al.add("QQ");
al.add("abc");
al.add("weixin");
al.add("abc");
System.out.println("删除前:"+al);
Iterator<String> it = al.iterator();
//int count = 0;
String line = "abc";
while(it.hasNext()){
String str = it.next();
if(line.equals(str)){
al.remove(str);
//count++;
}
}
System.out.println("删除后:"+al);
//System.out.println("本数组中共有"+count+"个abc");
}
}
|
|