Concurrent Modification exception

前端 未结 9 1455
谎友^
谎友^ 2020-11-22 14:36

I have this little piece of code and it gives me the concurrent modification exception. I cannot understand why I keep getting it, even though I do not see any concurrent mo

9条回答
  •  攒了一身酷
    2020-11-22 15:05

    This didn't work:

    LinkedList linkedList = new LinkedList();
    ListIterator listIterator = linkedList.listIterator();
    linkedList.add("aa");
    linkedList.add("bb");
    

    This worked:

    LinkedList linkedList = new LinkedList();
    linkedList.add("aa");
    linkedList.add("bb");
    ListIterator listIterator = linkedList.listIterator();
    

提交回复
热议问题