Created
April 26, 2013 13:42
-
-
Save cworks/5467458 to your computer and use it in GitHub Desktop.
Iterate over a Java Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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