ConcurrentModificationException in unmodifiable collection [duplicate]

↘锁芯ラ 提交于 2019-12-01 03:31:02

Be aware, that Collections.unmodifiable* is not copying collection data, but only wrapping the original collection in a special wrapper. So if you modify the original collection, you can get this error.


If you want to create really independent unmodifiable collection instance:

Collections.unmodifiableCollection(new ArrayList<>(map.values()));

You must be updating the map in another thread while you are iterating through col. Both map#values and Collections.unmodifiableCollection return views of existing data structures, so what you are iterating over (and this is witnessed by your stacktrace) is the entry set of your map.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!