Lesson 23Exploring Maps
This lesson continues the discussion of using collections by exploring the Map data structure, which is used for saving key/value pairs. In the lesson, we will primarily focus on the HashMap implementation and how to work with it in your code.
MAP INTERFACE
A Map is an object that maps keys to values. In general, a map models the concept of a mathematical function. In a map, each key can map to one and only one value, so it cannot contain duplicate keys.
While Maps are part of the Java Collections Framework, the Map interface itself is not a Collection (i.e., it does not extend the Collection interface, and it is not iterable); however, we can get a Collection of either the keys or the values of a Map or a Collection of Entry objects (both Key and Value).
The Map interface has many methods. In this lesson, we will cover the most often used methods, which are as follows:
get
put
keySet
size
values
Get Job Ready Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.