Note: SortedSet is an interface and TreeSet is its implementation class.
SortedSet:
public interface SortedSet<E>
extends Set<E>
All Known Subinterfaces:
NavigableSet<E>
All Known Implementing Classes:
ConcurrentSkipListSet, TreeSet
- SortedSet interface is a sub-interface of Set interface.
- SortedSet present in java.util package extends the Set interface present in the collection framework.
TreeSet:
public class TreeSet<E>
extends AbstractSet<E>
implements NavigableSet<E>, Cloneable, Serializable
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>, Set<E>, SortedSet<E>
NavigableSet:
All Superinterfaces:
Collection<E>, Iterable<E>, Set<E>, SortedSet<E>
All Known Implementing Classes:
ConcurrentSkipListSet, TreeSet
public interface NavigableSet<E>
extends SortedSet<E>
- TreeSet class is implementations of the SortedSet interface in Java that uses a Tree to store data.
- Elements or Objects are stored in a sorted and ascending order.
- Access and retrieval times are quite fast.
- TreeSet uses a self-balancing binary search tree, more specifically a Red-Black tree.
- TreeSet allows only unique element/objects to be inserted
- TreeSet object doesn't allows null values . If we try to store the null value in a TreeSet, this will thrown NullPointerException.
Related Tutorials
- Java Collections Interview
- List Interface In Java
- ArrayList
- LinkedList
- Custom Own ArrayList Implementation
- Custom LinkedList implementation in java
- Set Interface In Java
- Map Interface In Java
- HashMap
- TreeMap
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment