ConcurrentModificationException with LinkedHashMap

后端 未结 6 726
北恋
北恋 2021-02-04 03:09

Not sure what is triggering a java.util.ConcurrentModificationException when I iterate over the LinkedHashMap structure in the code below. Using the

6条回答
  •  轮回少年
    2021-02-04 03:45

    It is coz of fail-fast behaviour of collections framework also when you modify the list (by adding or removing elements) while traversing a list with this error will be there with Iterator. I came across this error some time back . Refer below threads to for detail info.

    ConcurrentModificationException when adding inside a foreach loop in ArrayList

    Though this says array list, it applies for most of the collection(s) data strucutres.

    Concurrent Modification Exception : adding to an ArrayList

    http://docs.oracle.com/javase/6/docs/api/java/util/ConcurrentModificationException.html

提交回复
热议问题