![]() |
VOOZH | about |
TreeSet is mainly an implementation of SortedSet in java where duplication is not allowed and objects are stored in sorted and ascending order.
Some important features of the TreeSet are:
TreeMap is an implementation of Map Interface. TreeMap is also an implementation of NavigableMap along with AbstractMap class.
Some important features of the TreeMap are:
Below is the illustration of TreeSet and TreeMap in Java:
Example 1:
[3, 4, 5]
{2=3, 3=5, 4=5}Example 2:
[FOR, geeks, tutorial]
{1=geeks, 2=FOR, 3=geeks, 4=tutorial}| S. No. | TreeSet | TreeMap |
|---|---|---|
| 1. | TreeSet implements SortedSet in Java. | TreeMap implements Map Interface in Java |
| 2. | TreeSet stored a single object in java. | TreeMap stores two Object one Key and one value. |
| 3. | TreeSet does not allow duplication Object in java. | TreeMap in java allows duplication of values. |
| 4. | TreeSet implements NavigableSet in Java. | TreeMap implements NavigableMap in Java. |
| 5. | TreeSet is sorted based on objects. | TreeMap is sorted based on keys. |