To delete a key-value pair, call .remove() with the key:
ages.remove("Bob");
This removes the entry and returns the value that was stored. If the key does not exist, it returns null and the map stays unchanged.
Java also offers a -argument version: .remove(key, value). This only removes the entry if both the key and value match:
ages.remove("Alice", 30); // does nothing if Alice is 31
ages.remove("Alice", 31); // removes Alice
The -argument form is useful when you need to guarantee you are removing the exact entry you expect, not a value that was updated by another part of your program.