What is the difference between HashMap
, LinkedHashMap
and TreeMap
in Java?
I don\'t see any difference in the output as all the three
While there are plenty of excellent Answers here, I'd like to present my own table describing the various Map
implementations bundled with Java 11.
We can see these differences listed on the table graphic:
HashMap
, adding this behavior: Maintains an order, the order in which the entries were originally added. Altering the value for key-value entry does not alter its place in the order.TreeMap
implements both the SortedMap interface, and its successor, the NavigableMap interface.TreeMap
does not allow a NULL as the key, while HashMap
& LinkedHashMap
do.
ConcurrentHashMap
obeys the same functional specification as Hashtable
, and includes versions of methods corresponding to each method of Hashtable
.