ConcurrentMapmap = new ConcurrentHashMap<>(); map.put("one", 1); map.put("two", 2); map.put("three", 3); Set > entrySet = map.entrySet(); for (Map.Entry entry : entrySet) { System.out.println(entry.getKey() + " = " + entry.getValue()); }
ConcurrentMapIn this example, we create a ConcurrentHashMap, add some key-value pairs to it, and get a set of Map.Entry objects using the entrySet() method. We then iterate over the set using a for-each loop and update the value of the entry with the key "two" from 2 to 4. Finally, we print out the updated map. The ConcurrentMap interface and its entrySet() method are part of the java.util.concurrent package library.map = new ConcurrentHashMap<>(); map.put("one", 1); map.put("two", 2); map.put("three", 3); Set > entrySet = map.entrySet(); for (Map.Entry entry : entrySet) { if (entry.getValue() == 2) { entry.setValue(4); } } System.out.println(map);