Map in Java

Beknazar
2 min readMar 30, 2022

--

The map is a set of key-value mappings. The keys are unique.

HashMap class is a hash table based implementation of the Map:
1. Does not maintain any order.
2. Allows one null as a key and any number of null as a value.
3. Unsynchronized.

Hashtable. This class implements a hash table, which maps keys to values. Any non-null an object can be used as a key or as a value:
1. Does not maintain any order.
2. Does not allow null as key and value.
3. Synchronized.

LinkedHashMap class is a hash table and linked list based implementation of the Map interface. The difference from HashMap is that it maintains a doubly-linked list to provide insertion(iteration) order. Note that insertion order is not affected if a key is re-inserted into the map.

TreeMap class — Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

--

--

Beknazar
Beknazar

No responses yet