Iterator迭代器并发修改异常问题解决
生活随笔
收集整理的這篇文章主要介紹了
Iterator迭代器并发修改异常问题解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public static void main(String[] args) {//method();//創建集合對象//Collection c = new ArrayList();List c = new ArrayList();//添加元素c.add("hello");c.add("world");c.add("java");//我們可以通過遍歷來獲取集合中的每一個元素,然后進行比較即可(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);}
?
總結
以上是生活随笔為你收集整理的Iterator迭代器并发修改异常问题解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Springboot2.0的Dubb
- 下一篇: spring aop记录日志方案设计