ConcurrentModificationException

来源:互联网 发布:网络心理咨询师招聘 编辑:程序博客网 时间:2024/04/29 20:24


http://stackoverflow.com/questions/1496180/concurrent-modification-exception


Between creating the iterator and starting to use the iterator, you added arguments to the list that is to be iterated. This is a concurrent modification.

    ListIterator<String> it = s.listIterator();      for (String a : args)        s.add(a);                    // concurrent modification here    if (it.hasNext())        String item = it.next();     // exception thrown here

Create the iterator AFTER you've finished adding elements to the list:

    for (String a : args)        s.add(a);     ListIterator<String> it = s.listIterator();      if (it.hasNext())        String item = it.next();
0 0
原创粉丝点击