ConcurrentModificationException when using iterator and iterator.remove()

前端 未结 4 1937
旧时难觅i
旧时难觅i 2021-01-13 16:30
    private int checkLevel(String bigWord, Collection dict, MinMax minMax)
{
    /*value initialised to losing*/
    int value = 0; 
    if (minMax ==          


        
4条回答
  •  鱼传尺愫
    2021-01-13 16:40

    This is a common occurance in all Collections classes. For instance the entry in TreeSet uses failfast method.

    The iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

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

提交回复
热议问题