You add a key-value pair to a HashMap with the .put() method:
HashMap<String, Integer> ages = new HashMap<>();
ages.put("Alice", 30);
ages.put("Bob", 25);
ages.put("Carol", 28);
After these calls, the map contains entries. If you call .put() again with an existing key, the value gets overwritten:
ages.put("Alice", 31); // Alice is now 31, not 30
The .put() method returns the previous value if the key already existed, or null if it was a new key. That return value is easy to overlook, but it becomes useful when you need to detect whether an entry was replaced.