Its astounding how often I find maps being used like this.
for(String name: names.keySet()) {
mymap.put(mymap.get(name),name);
}
Its inefficient because you have to fetch the keys and perform a lookup in the map with the key.
Instead using the EntrySet you can get all the keys and values in one hit. This saves having to perform the map lookup.
for (Entry<String, String> entry : entrySet) {
mymap.put(entry.getValue(),entry.getKey());
}













yeah, these mistakes are far too common. i have used findbugs in the past to flag these down
Ha! It was poking over some findbugs reports, and cleaning up that lead to this comment!