I\'ve got a map containing some keys (Strings) and values (POJOs)
I want to iterate through this map and alter some of the data in the POJO.
The current code
Iterating over a Map and adding entries at the same time will result in a ConcurrentModificationException for most Map classes. And for the Map classes that don't (e.g. ConcurrentHashMap) there is no guarantee that an iteration will visit all entries.
Depending on exactly what it is you are doing, you may be able to do the following while iterating:
Iterator.remove() method to remove the current entry, orMap.Entry.setValue() method to modify the current entry's value.For other types of change, you may need to:
Map from the entries in the current Map, or Map.And finally, the Google Collections and Apache Commons Collections libraries have utility classes for "transforming" maps.