原文:https://www.iteye.com/blog/czj4451-1474047
若需要删除,则需要修改指针位置
错误代码
//创建集合对象
Collection<Student> c = new ArrayList<>();
Student s1 = new Student("林青霞",2);
Student s2 = new Student("看八字",22);
Student s3 = new Student("小小", 2);
c.add(s1);
c.add(s2);
c.add(s3);
Iterator<Student> i = c.iterator();
int a=0;
while(i.hasNext()){
if(a==1){
a +=1;
c.remove(i.next());
continue;
}
a +=1;
System.out.println(i.next());
}