I have a linkedlist where each element has key and value(ArrayList<dataStructure>
). I want to merge the elements having same key.
Iterator<CElem> oItr = linkedList.iterator();
{
while (oItr.hasNext())
{
CElem outer = oItr.next();
Iterator<CElem> iItr = linkedList.iterator();
{
while (iItr.hasNext())
{
CElem inner = iItr.next();
if (outer.equals(inner))
continue;
if (outer.getKey().equals(inner.getKey()))
{
outer.getValues().addAll(inner.getValues());
iItr.remove();
}
}
}
}
}
Though I am using the iterators remove methog getting a java.util.ConcurrentModificationException
. What should be changed to get rid of this.