Java Map
The collection interface that associates each unique key with one value, replacing the old value when a key is stored again.
In more detail
get(key) looks a value up and put(key, value) stores one. HashMap iterates in no particular order; LinkedHashMap keeps insertion order, which matters when a map is displayed or serialized. Collectors.groupingBy produces a map from a key to the values sharing it.
Example
private final Map<String, Integer> positions = new LinkedHashMap<>();Related terms
- Java Collections Framework — The standard library's set of interfaces and classes for groups of objects, chiefly List, Set and Map, and their implementations.
- hash code — An int that an object computes from its contents so hash-based collections such as HashMap can find it quickly.
- collector — A recipe passed to a stream's collect operation that gathers the elements into a result, such as a set or a map grouped by key.
Taught in
- The Collections Framework — Modern Java: Virtual Threads & High-Throughput Services
- The Streams API — Modern Java: Virtual Threads & High-Throughput Services
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Generics, Bounds And Wildcards — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Exceptions, Arrays And Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Stream Pipelines, Primitive Streams And Optional — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Reduction, Grouping And Partitioning — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Concurrent Collections And Parallel Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
References
- Java SE 21 API: Map
- Java Tutorials: The Map Interface
- dev.java: Using Maps
- Java SE 21 API: LinkedHashMap