map.replace(key, map.get(key) + 1);
//or
map.put(key, map.get(key) + 1);
import java.util.HashMap;
class Main {
public static void main(String[] args) {
HashMap<Integer, String> languages = new HashMap<>();
languages.put(1, "Java");
languages.put(2, "Python");
languages.put(3, "JavaScript");
System.out.println("Original HashMap: " + languages);
// change element with key 2
languages.replace(2, "C++");
System.out.println("HashMap using replace(): " + languages);
}
}