Friday, April 11, 2008

ConcurrentModificationException

Problem Def: java.util.ConcurrentModificationException, occurs when you iterate thur and modify the same List of values.

Solution: Tried using a for loop, List.iterator, Collections.synchronizedList() all in vain. With for loop, I often ran into array index out of bound. Using iterator got ConcurrentModification error. So the solution is copy your values into another list and modify new list while iterating the old one.

Wait a minute.. googling longer found a better answer.. you should use iterator.remove() yay..!!! effective way of all:D


Lesson learnt: Patience pays off


Happy reading
Sunny
-------------

No comments: