ConcurrentModificationException (Java)

后端 未结 3 1131
北恋
北恋 2020-12-18 08:05
Exception in thread \"main\" java.util.ConcurrentModificationException
Squash the PC dirties the room Violet. The room\'s state is now dirty
Lily the animal growls
T         


        
3条回答
  •  别那么骄傲
    2020-12-18 08:55

    The only safe way to remove an element from an underlying collection and continue the iteration is to use the remove() method of the Iterator. This removes the last element returned by the next() method of the Iterator.

    In your case, it appears that this would require passing the Iterator to the method that performs the modification (or make it an instance field, like the Map object is already).

提交回复
热议问题