Changing HashMap keys during iteration
Maybe this helps:
map.put(newkey,map.remove(oldkey));
You should keep information in other collection to modify it after iteration. You can only remove entry using iterator.remove()
during iterator. HashMap
contract forbids mutating it during iteration.