Hi, I want to remove an item from the HashMap by applying criteria. Consider this code:
Set set = myMap.keySet();
Iterator itr = set.iterator();
while (itr.hasNext())
{
Object o = itr.next();
if (o.toString().length() < 3) {
myMap.remove(o.toString());
}
So, I get the ConcurentModification Exception runtime because during the iteration I modify the HashMap. What should I do? Are there any other ways to search my criteria and run the remove command at the end so that I can avoid this exception?
Mavin source
share