The Map ADT

Solution

A map is a collection of key–value pairs with distinct keys and no order. put(key, value) stores the value under the key; if the key is already present, it replaces the old value. get(key) returns the value stored under the key, or null if the key is absent. remove(key) takes the key and its value out of the map if the key is present. containsKey(key) reports whether the key is in the map. size() reports how many pairs the map holds.

Solution
map.put("oak", 12);       true
map.put("elm", 35);       true
map.put("oak", 47);       false
map.get("oak");           47
map.get("fir");           null
map.containsKey("elm");   true
map.remove("fir");        false
map.remove("elm");        true
map.size();               1
Solution

get returns null when the key is absent. If no key can ever lead to a null value, then a null from get can only mean that the key is absent.