Problems while removing an Element from LinkedHashMap

M

Markus Innerebner

Hello

I 've got following problem:
I am working with LinkedHashMap for a set of objects ( called currentCO ).
now I want remove one Element from currentCO and insert in a second
LinkedHashMap. Then sequentially I want remove the next Element in
currentCO and reinsert in the second LinkedHashMap.
Code is:

LinkedHashMap _currentCO, successors;
.........
// here is the relevant Code where I do this operation.
Iterator it2 = _currentCO.values().iterator();
while (it2.hasNext()) {
if ( ( (Objekt) it2.next()).getCOPosition() == minCOPOS - 1) {
while (it2.hasNext()) {
Objekt succObj = (Objekt) it2.next();
succObj.setCOPosition(COPOSCOUNTER++);
successors.put(new Integer(succObj.getId()), _currentCO.remove(new Integer(succObj.getId())));
}
}
}

When starting the program I get always this Exception: java.util.ConcurrentModificationException
Please can somebody help me. I really don't know what did I wrong.

thank you

Markus Innerebner
 
M

Markus Innerebner

Hello to all:
i think I found my mistake
i have to remove the element from _currentCO with it2.remove()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top