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:集合遍历元素,集合修改元素
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!