Map (HashMap, TreeMap)

Map associates unique keys with values. HashMap is fast with no guaranteed order, LinkedHashMap keeps insertion order, TreeMap sorts by key. Common methods: put, get, getOrDefault, containsKey, merge, computeIfAbsent. The key relies on equals and hashCode.

Example

Map<String, Integer> stock = new HashMap<>();
stock.merge("apple", 1, Integer::sum);

Related concepts

The whole glossary