Skip to content

Instantly share code, notes, and snippets.

@cworks
Created April 26, 2013 13:42
Show Gist options
  • Save cworks/5467458 to your computer and use it in GitHub Desktop.
Save cworks/5467458 to your computer and use it in GitHub Desktop.
Iterate over a Java Map
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment