I was writing a sample program to demonstate how to remove elments from list while iterating over it by using Iterator.remove() mehtod. Unfortunately I was getting following error, right at the place where I was calling the Iterator.remove() method :
Exception in thread "main" java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(Unknown Source)
at dto.IteratorRemoveTest.main(IteratorRemoveTest.java:25)
I was puzzled, why I am getting this error because I was using Iterator's remove() method and not the ArrayList's remove() method, which causes ConcurrentModificationException in Java.
Read more »
Exception in thread "main" java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(Unknown Source)
at dto.IteratorRemoveTest.main(IteratorRemoveTest.java:25)
I was puzzled, why I am getting this error because I was using Iterator's remove() method and not the ArrayList's remove() method, which causes ConcurrentModificationException in Java.
