java.util · java.base · since Java 1.2
Map
public interface Map<K, V>Key → value associations. The modern default methods (getOrDefault, computeIfAbsent, merge) eliminated most manual null-dancing.
Key methods
V get(Object key) / V put(K key, V value) | Core lookup/store; get returns null on miss, put returns the previous value or null. |
V getOrDefault(Object key, V default) | Miss-safe read — no null check needed. |
V putIfAbsent(K, V) | Conditional insert — returns the existing value if present, null if it inserted. |
V computeIfAbsent(K, Function<K,V>) | Get-or-create in one call — the standard multimap/cache idiom; the function is not invoked when a mapping already exists. |
V computeIfPresent(K, BiFunction<K,V,V>) | Update-if-present; returning null from the function removes the entry. |
V compute(K, BiFunction<K,V,V>) | Unconditional read-modify-write — the function sees null for a missing key, and a null result removes the entry. |
V merge(K, V, BiFunction<V,V,V>) | Insert-or-combine — counting and summing in one line; a null result removes the entry. |
void forEach(BiConsumer<K,V>) | Traverse key+value pairs without an explicit entrySet() loop. |
void replaceAll(BiFunction<K,V,V>) | In-place transform of every value. |
Set<K> keySet() / Collection<V> values() / Set<Map.Entry<K,V>> entrySet() | Live views over the map — removal through any of them writes through to the map. |
static <K,V> Map<K,V> of(K,V,…) / ofEntries(Entry…) / entry(K,V) | Immutable literals — of() covers up to 10 pairs, ofEntries() any number, entry() builds one Map.Entry. |
static <K,V> Map<K,V> copyOf(Map) | Immutable defensive copy. |