On this page
  1. Map
  2. Import
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

Map

Prev: `List` | Up: java.util | Next: `Set`
Rel: java.util, java/builtins
Ref: Java Docs — Map
Tags: #public #prog #java #stdlib #java_util #tier/core


Import

import java.util.*;

Signature & Overview

Map<K, V>  /* HashMap, LinkedHashMap, Map.of(...) */

Key-value mapping with atomic helpers .computeIfAbsent(), .merge(), and .getOrDefault().

Notes & Pitfalls

Example

import java.util.*;

var counts = new HashMap<String, Integer>();
for (var w : List.of("java", "ok", "java")) {
    counts.merge(w, 1, Integer::sum);
}
assert counts.get("java") == 2;

Linked from

Related notes