Java , Removing object from ArrayList

前端 未结 4 452
独厮守ぢ
独厮守ぢ 2021-01-16 23:02

I have ClassA which has a static ArrayList of Objects

public static ArrayList meteorits = new ArrayList();

4条回答
  •  逝去的感伤
    2021-01-16 23:38

    When using an iterator; you need to use the iterator to remove items from a list using this:

    iterator.remove();
    

    which from the Java Docs says:

    Removes from the underlying collection the last element returned by this iterator.

    Removing a item from the list by any other means will result in the ConcurrentModificationException you are seeing.

提交回复
热议问题