Answers for "loop through hashmap to get key and value"

2

loop hash map

public static void printMap(Map mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        System.out.println(pair.getKey() + " = " + pair.getValue());
        it.remove(); // avoids a ConcurrentModificationException
    }
}
Posted by: Guest on April-26-2020

Code answers related to "loop through hashmap to get key and value"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language