public class IteratorTest {
public static void main(String[] args) {
List list = new ArrayList();
for (int i=0;i < 10; i++){
list.add(“aaa”+i);
}
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()){
list.remove("aaa1");
iterator.next();
//iterator.remove();
}
System.out.println(list);
}
}
//不能用集合的删除方法,因为迭代过程中如果集合修改会出现并发修改异常(ConcurrentModificationException)