I wanted to iterate over an ArrayList and remove the elements, but I am getting an error: "java.util.ConcurrentModificationException".
My code:
public class Test() {
private ArrayList<A> abc = new ArrayList<A>();
public void doStuff() {
for (A a : abc)
a.doSomething();
}
public void removeA(A a) {
abc.remove(a);
}
}
What is the best practice to handle this problem? Should I clone the list first?