View Full Version : Java concurrentModificationException

17-10-2002, 02:24 AM

i have an array list of sets that i am trying to iterate through.
My array list is synchronised and i have two iterators that iterate through the array
and compare one set to another and then i define two iterators on the sets in the array and
compare the elements in each set. The problem is that i get a concurrentModificationException

I have tried two approaches to defining the set and its iterator, the componentListItr1 and
componentListItr2 Iterators are the iterators over the synchronized arraylist, both of which
throw the same Exception:

Appraoch 1:

Set componentSubset1 = (Set)componentListItr1.next();
Set componentSubset2 = (Set)componentListItr2.next();

Approach 2:

Set componentSubset1 = Collections.synchronizedSet(new HashSet());
componentSubset1.addAll((Set)componentListItr1.nex t());

Set componentSubset2 = Collections.synchronizedSet(new HashSet());
componentSubset2.addAll((Set)componentListItr2.nex t());


an expat Kiwi