Mapmap = new HashMap<>(); map.put("One", 1); map.put("Two", 2); map.entrySet().stream() .filter(e -> e.getKey().equals("One")) .findFirst() .ifPresent(e -> e.setValue(10)); System.out.println(map); // Prints {One=10, Two=2}
import java.util.AbstractMap.SimpleEntry; SimpleEntryIn this example, we create a new `SimpleEntry` with a key of "One" and a value of 1. We then call `setValue()` on the entry to change its value to 10. Package library: `java.util`entry = new SimpleEntry<>("One", 1); entry.setValue(10); System.out.println(entry); // Prints One=10