Java Map : There are no duplicate values allowed in the map. A map object’s keys must be unique. HashMap, TreeMap, and LinkedHashMap are three groups that implement the Map interface in the Java collection system. SortedMap is a special interface for keeping all of the elements sorted.

HashMap vs LinkedHashMap

The ordering of the elements is the main difference between HashMap and LinkedHashMap. Only one null key and multiple values are allowed in HashMap and LinkedHashMap. The HashMap class extends AbstractMap and implements the Map interface, while the LinkedHashMap class extends HashMap and implements the Map interface.

Hashmap vs TreeMap

A single null key and multiple null values are allowed in HashMap. TreeMap does not allow null keys, but multiple null values are permitted. Since HashMap does not sort on keys, it allows for heterogeneous items. Because of the sorting, TreeMap allows homogeneous values to be used as a key.

References :

Laisser un commentaire