我在编写旅行推销员计划时遇到了这个问题.对于内循环,我尝试了一个
for(Point x:ArrayList<Point>) { // modify the iterator }
但是当向该列表添加另一个点时会导致ConcurrentModicationException被抛出.
但是,当我将循环更改为
for(int x=0; x<ArrayList<Point>.size(); x++) { // modify the array }
循环运行良好,不会抛出异常.