ConcurrentModificationException and a HashMap

Iterator it = map.entrySet().iterator();while(it.hasNext()){Entry item = it.next();
   map.remove(item.getKey());}

这种方法会出现错误

正确的删除办法是

Iterator it = map.entrySet().iterator();

   while (it.hasNext())

   {

      Entry item = it.next();

      it.remove();

   }

猜你喜欢

转载自soledede.iteye.com/blog/2351535