Concurrent modification error when adding elements to LinkedList

后端 未结 3 1836
长情又很酷
长情又很酷 2021-01-24 01:09

I have an List of LinkedList objects.

    List> backup = new ArrayList>();

The Link

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-24 01:15

    First, if you really expect people to give their attention to your question, you should do them the favor of asking it clearly and in standard English.

    Second, you should provide an indication of exactly where in your code you're getting the ConcurrentModificationError.

    Finally, what is it_bk? It just shows up in your code without any explanation. If it is an ArrayList of ListIterators it is certainly possible that its parent_node-th element is in a state where it isn't sure that hasNext() or next() will be safe. I'm guessing you modified the underlying collection with your tmp_bk.add(f_new); and so a pre-existing iterator is worried that its invariants may be violated.

    General advice: Don't create and retain iterators (or collections of them). When you want an Iterator, create it, use it, and abandon it.

提交回复
热议问题