for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
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);
});
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
for(Map.Entry<String, Integer> entry : hashMap.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
//do something with the key and value
}
map.forEach((k, v) -> {
System.out.format("key: %s, value: %d%n", k, v);
});
// Java program to demonstrate iteration over
// Map.entrySet() entries using for-each loop
import java.util.Map;
import java.util.HashMap;
class IterationDemo
{
public static void main(String[] arg)
{
Map<String,String> gfg = new HashMap<String,String>();
// enter name/url pair
gfg.put("GFG", "geeksforgeeks.org");
gfg.put("Practice", "practice.geeksforgeeks.org");
gfg.put("Code", "code.geeksforgeeks.org");
gfg.put("Quiz", "quiz.geeksforgeeks.org");
// using for-each loop for iteration over Map.entrySet()
for (Map.Entry<String,String> entry : gfg.entrySet())
System.out.println("Key = " + entry.getKey() +
", Value = " + entry.getValue());
}
}
for (const [key, value] of myMap) {
console.log(key + ' = ' + value)
}
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
}
}
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
}
}