Answers for "looping through a hashmap"

31

java iterate through hashmap

for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
	System.out.println(entry.getKey() + " = " + entry.getValue());
}
Posted by: Guest on April-13-2020
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 "looping through a hashmap"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language