This error occurs because you are trying to resize a collection during iteration. If you have 10 students, you start your loop expecting to go through 10 iterations. When you delete a student, how many iterations still need to go? The answer, obviously, depends on where you removed your student from the list and where you are currently in your lawsuit. Obviously, java cannot know this.
To get around this, you should use an iterator. You can accomplish this as follows:
Iterator<Student> studentsIterator; for(studentsIterator = students.iterator(); studentsIterator.hasNext();) { Student student = studentsIterator.next(); if(student... ) { studentIterator.remove();
mmoore
source share