Why does one loop throw a ConcurrentModificationException, while the other doesn't?

后端 未结 5 1709
余生分开走
余生分开走 2020-12-16 18:40

I\'ve run into this while writing a Traveling Salesman program. For an inner loop, I tried a

for(Point x:ArrayList) {
// modify the iterator
}         


        
5条回答
  •  情话喂你
    2020-12-16 19:23

    The first example uses an iterator, the second does not. It is the iterator that checks for concurrent modification.

提交回复
热议问题