1.Iterate through the "EntrySet" like so:
Public Static void Printmap (Map MP) { = mp.entryset (). iterator (); while (It.hasnext ()) { = (map.entry) It.next (); + "=" + Pair.getvalue ()); // avoids a concurrentmodificationexception }}
2.If interested in the keys and you can iterate through the "KeySet ()" of the map:
map<string, object> map = ...; for (String key:map.keySet ()) { // ...}
3.If need the values, use "value ()":
for (Object value:map.values ()) { // ...}
4.Finally, if you want both the key and value, use "EntrySet ()":
for (map.entry<string, object> entry:map.entrySet ()) { = entry.getkey (); = Entry.getvalue (); // ...}
Summary,if need only keys or values from the map, use method #2 or method #3. If you is stuck with older version of Java (less than 5) or planning to remove entries during iteration Method #1. Otherwise use Method #4.
How to iterate through a Map in Java?