Set Interface In Java :
- Set is an interface.
- its belongs to java.util package and extends the Collection interface.
- It is an unordered collection of objects.
- Set is a collection of unique elements.It does not allow duplicate elements means no duplicate elements.
- It allow only one null element.
public interface Set<E>
extends Collection<E>
All Known Subinterfaces:
NavigableSet<E>, SortedSet<E>
All Known Implementing Classes:
AbstractSet, ConcurrentHashMap.KeySetView, ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, HashSet, JobStateReasons, LinkedHashSet, TreeSet
SortedSet Interface :
public interface SortedSet<E>
extends Set<E>
All Known Implementing Classes:
ConcurrentSkipListSet, TreeSet
All Known Subinterfaces:
NavigableSet<E>
Implementation of Set
- HashSet
- LinkedHashSet
- SortedSet : It is a sub-interface of set interface.
- TreeSet : TheeSet is an implementation class of SortedSet. TreeSet has O(log(n)) time complexity for the add(), remove() and contains() operations because of the TreeMap implementation internally.
- EnumSet
- CopyOnWriteArraySet : CopyOnWriteArraySet is a thread-safe variant of HashSet, its uses a CopyOnWriteArrayList internally for all of its operations. The add(), remove() and contains() methods have O(n) average time complexity.
- ConcurrentSkipListSet : ConcurrentSkipListSet have O(log(n)) time complexity for add(), remove() and contains(), as it's based in skip list data structure.
Time complexity For HashSet, LinkedHashSet, and EnumSet, the add(), remove()
and contains() operations cost constant O(1) time. These are uses HashMap
internally.
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