Answers for "accessing hashmap using foreach loop"

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
0

hashmap.foreach example

hashmap.forEach((key,value) -> {
	//do some things
})
Posted by: Guest on July-19-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language