ConcurrentModificationException using Iterator

前端 未结 2 1919
迷失自我
迷失自我 2021-01-27 23:24

I\'m using an iterator to loop over a collection as follows:

Iterator entityItr = entityList.iterator(); 

    while (entityItr.hasNext())
    {
           


        
2条回答
  •  独厮守ぢ
    2021-01-28 00:02

    It looks that there is another thread using the same collection and modifing it when this code is iterating over the collection.

    ConcurrentModificationException

    You can use navite java concurrent collestions instead. They are thread safe. However it's a good habbit to create immutable collections - they are thread safe and enforce you to design reliable code.

提交回复
热议问题