Answers for "java iterate over 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
6

how to iterate hashmap in java

for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
	System.out.println(entry.getKey() + " = " + entry.getValue());
}

map.forEach((k, v) -> {
    System.out.format("key: %s, value: %d%n", k, v);
});
Posted by: Guest on June-06-2020
5

java for map

Map<String, String> map = new HashMap<>();

for(Entry<String, String> entry:map.entrySet()) {
  System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
}
Posted by: Guest on July-07-2020
1

java iterate through map

for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    // ...
}
Posted by: Guest on May-25-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
1

iterating over a hashmap

for(Map.Entry<String, Integer> entry : hashMap.entrySet()) {
    String key = entry.getKey();
    Integer value =  entry.getValue();
    //do something with the key and value
}
Posted by: Guest on November-19-2020

Code answers related to "java iterate over hashmap"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language