源码

首页 » 归档 » 源码 » java – 为什么我在同时在HashMap上进行迭代…

java – 为什么我在同时在HashMap上进行迭代…


我有一张地图

Map map = new HashMap();

map.put("Pujan", "pujan");
map.put("Swati", "swati");
map.put("Manish", "manish");
map.put("Jayant", "jayant");
Iterator> itr = map.entrySet().iterator();
while(itr.hasNext()){
  Entry entry=(Entry) itr.next();
  map.put("Manish", "Updated");
}

我在这里没有例外(我试图修改现有的键值“Manish”).但是如果我尝试添加一个新的键map.put(“Manish123”,“Updated”),我会得到ConcurrentModificationException.

(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/java-weishenmewozaitongshizaihashmapshangjinxingdiedai.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:11月 11, 2019 at 04:37 下午

热评文章