Possible Duplicate:
Efficient equivalent for removing elements while iterating the Collection
private LinkedList flights;
....
public void clear(){
ListIterator itr = flights.listIterator();
while(itr.hasNext()){
flights.remove(itr.next());
}
}
....
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
at java.util.LinkedList$ListItr.next(Unknown Source)
at section1.FlightQueue.clear(FlightQueue.java:44)
at section1.FlightTest001.main(FlightTest001.java:22)
Whats wrong with it? cant at all understand why the error is given, I am sure i have used the same code on arraylists or arrays and it has worked.