【发布时间】:2012-12-24 08:12:46
【问题描述】:
ConcurrentModificationException 有问题。
我定义了一个 ArrayList 的 Complex 类。我添加了两个Complexes,并尝试为每个循环做一个,但我得到了ConcurrentModificationException。但是,当我删除该行时,我没有收到任何错误。我需要这些初始点 (1,0)、(-1,0) 来计算我以后需要的点。
for (Iterator<Complex> num = dots.iterator(); num.hasNext();) {
// ConcurrentModificationException
Complex aComplex = num.next();
// clone it and clear
temp.add(new Complex(aComplex));
dots.clear();
}
【问题讨论】:
-
不应该
dots.clear()和temp.clear()在对应的for之外吗?
标签: java arraylist java.util.concurrent concurrentmodification