Iterator迭代器并发修改异常问题解决
生活随笔
收集整理的這篇文章主要介紹了
Iterator迭代器并发修改异常问题解决
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
public static void main(String[] args) {//method();//創(chuàng)建集合對(duì)象//Collection c = new ArrayList();List c = new ArrayList();//添加元素c.add("hello");c.add("world");c.add("java");//我們可以通過(guò)遍歷來(lái)獲取集合中的每一個(gè)元素,然后進(jìn)行比較即可(java.util.ConcurrentModificationException)/*Iterator it = c.iterator();while(it.hasNext()) {String s = (String)it.next();if(s.equals("java")) {c.add("android");}}*/ListIterator lit = c.listIterator();while(lit.hasNext()) {String s = (String)lit.next();if(s.equals("java")) {lit.add("android");}}System.out.println(c);}
?
總結(jié)
以上是生活随笔為你收集整理的Iterator迭代器并发修改异常问题解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于Springboot2.0的Dubb
- 下一篇: spring aop记录日志方案设计