hashmap使用出现java.util.ConcurrentModificationException 错误
hashmap在使用时如果一边遍历,一边对集合进行修改操作,就很可能抛出java.util.ConcurrentModificationException 异常
错误具体原因
可见此博客HashMap中ConcurrentModificationException异常解读
从源码分析,十分清楚
修改办法
使用hashmap的entryset视图的Iterator方法进行遍历迭代,在其中进行修改操作就不会抛出异常
删除时不能使用map.remove(key),否则也报ConcurrentModificationException
只能使用iterator.remove
具体修改操作及案例可见map遍历删除异常