Map

A Map pairs keys and values. If we want to approach a Map from the Collection point of view, then a Map is a collection of key/value pairs. You can put key/value pairs into a Map and you can get a value based on a key. Keys are unique in the same way as elements in a Set. If you look at the source code of the different implementations of the Set interface, you may see that some of them are implemented as a wrapper around a Map implementation where the values are simply discarded.

The interface defines a lot of methods. The two most important methods are put() and get(). The put(key,value) method can be used to store a key/value pair in the map. If there is a pair that has a key that equals() the key we want to set in the pair, then the ...

Get Java Projects - Second Edition 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.