当我从哈希映射中删除一个元素获取并发修改异常 [英] when i removing one element from hash map getting concurrent modification exception

查看:49
本文介绍了当我从哈希映射中删除一个元素获取并发修改异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



这是我的代码检查这一个



Good day to all,

this is my code check this one

while (ir.hasNext()) {
  Map.Entry me = (Map.Entry) ir.next();
  Log.v("remove items ", "" + Integer.parseInt(me.getKey().toString()));
  if (Integer.parseInt(me.getKey().toString()) == closeImage.getId()
      && Integer.parseInt(me.getKey().toString()) == orderImage.getId()) {
	System.out.print(me.getKey() + ": ");
	System.out.println(me.getValue());
	orderItemsMap.remove(me.getKey());
  }
}

推荐答案

因为您在更改项目时使用了hashmap。这不起作用。



如何在使用迭代器时避免ConcurrentModificationException [ ^ ]
Because you''re using the hashmap while changing the item. That does not work.

How to Avoid ConcurrentModificationException when using an Iterator[^]


这篇关于当我从哈希映射中删除一个元素获取并发修改异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆