可能重复:
LinkedList 迭代器删除
private LinkedList flights;
...
public FlightQueue() {
super();
flights = new LinkedList();
}
...
public void clear(){
ListIterator itr = flights.listIterator();
while(itr.hasNext()){
itr.remove();
}
}
……
Exception in thread "main" java.lang.IllegalStateException
at java.util.LinkedList$ListItr.remove(Unknown Source)
at section1.FlightQueue.clear(FlightQueue.java:44)
at section1.FlightTest001.main(FlightTest001.java:22)
不知道出了什么问题,它在第一个 itr.remove() 处显示错误。