Know Also : Map / HashMap / TreeMap / AbstractMap / NavigableMap
HashMap
|
TreeMap
|
It doesn’t maintain insertion order of elements.
|
TreeMap by default maintain natural order of
elements i.e ascending order.
|
It allows one null key and multiple null values.
|
It doesn’t allow null as a key or as a value.
|
Its performance is fast because it doesn’t maintain
any order.
|
Its performance is slow in comparison to HashMap because
it maintains element order.
|
It internally uses Hashing.
|
It internally uses Red Black Tree.
|
TreeMap is rich in functionality because it has
some methods like pollFirstEntry(), pollLastEntry(), tailMap(), firstKey(),
lastKey() etc.
|
|
HashMap uses equal() method for comparison.
|
TreeMap uses campareTo() method for comparison.
|
HashMap implements Map Interface.
|
TreeMap implements NavigableMap Interface.
|
HashMap
|
TreeMap
|
It is not synchronized.
|
It is not synchronized.
|
It is not Thread-safe.
|
It is not Thread-safe.
|
It is a fail-fast iterator.
|
It is a fail-fast iterator.
|
It extends AbstractMap class.
|
It extends AbstractMap class.
|
Hashmap can be synchronized by using :
HashMap<String, String> map = new HashMap<>();
Collections.synchronizedMap(map);
|
TreeMap can be synchronized by using :
TreeMap<String, Integer> treemap = new
TreeMap<>();
Collections.synchronizedSortedMap(treemap);
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

No comments:
Post a Comment