- A map contains values based on the key i.e. key and value pair.Each pair is known as an entry.Map contains only unique elements.
- The Map interface represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface. Therefore it behaves a bit different from the rest of the collection types.
Since Map is an interface you need to instantiate a concrete implementation of the interface in order to use it. We can choose between the following Map implementations in the Java Collections API:
In my point of view, the most commonly used Map implementations are HashMap and TreeMap.Here are a few examples of how to create a Map instance:
Map m = new HashMap();
Map m = new TreeMap();