使用Iterator的方式也可以顺利删除和遍历
使用Iterator的方式也可以顺利删除和遍历
eg:public voiditeratorRemove() {
List<Student> students = this.getStudents();
System.out.println(students);
Iterator<Student> stuIter =students.iterator();while(stuIter.hasNext()) {
Student student=stuIter.next();if (student.getId() % 2 == 0)
stuIter.remove();
}
System.out.println(students);
}