- A TreeMap contains values based on the key. It implements the NavigableMap interface and extends AbstractMap class.
- It contains only unique elements.
- It cannot have null key but can have multiple null values.
- It is same as HashMap instead maintains ascending order.
Hierarchy of TreeMap class:
Example of TreeMap class:
Output:100 Amit 101 Vijay 102 Ravi 103 Rahul
What is difference between HashMap and TreeMap?
1) HashMap is can contain one null key. | TreeMap can not contain any null key. |
2) HashMap maintains no order. | TreeMap maintains ascending order. |
No comments:
Post a Comment