terator的方式也可以顺利删除和遍历

terator的方式也可以顺利删除和遍历

使用Iterator的方式也可以顺利删除和遍历
eg:
public void iteratorRemove() {
        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);
} 
05-02 18:46