Sometimes I find myself duplicating code to extract both key and value entries from a Map (when testing/debugging a third-party API, for example).
Map<String, String> someMap;
Set<String> keys = someMap.keySet();
for(int j=0;j<someMap.size();j++){
String key = (String) keys.toArray()[j];
System.out.println("key > " + key + " : value = " + someMap.get(key));
}
I know Groovy has some great abstractions for this (e.g. Get key in groovy maps), but I'm constrained to POJ. Surely there must be a more elegant and less verbose way to do this, in Java I mean?