ConcurrentModificationException并发修改异常

A:ConcurrentModificationException出现:

/*Iterator it = list.iterator(); //获取迭代器

while(it.hasNext()) { //判断集合中是否有元素

String str = (String)it.next(); //向下转型

if("world".equals(str)) {

list.add("javaee"); 

//遍历的同时在增加元素,并发修改ConcurrentModificationException

}

}*/

B:解决方案

* a:迭代器迭代元素,迭代器修改元素(ListIterator的特有功能add)

* b:集合遍历元素,集合修改元素

原文地址:https://www.cnblogs.com/loaderman/p/6407359.html