Difference and similarities between HashSet, LinkedHashSet and TreeSet in Java
Last Updated :
12 Aug, 2022
In this article, we will learn, the difference between HashSet vs LinkedHashSet and TreeSet And similarities between LinkedHashSet and TreeSet. HashSet, LinkedHashSet, and TreeSet all implement the Set interface. So we have tried to list out the differences and similarities between HashSet, LinkedHashSet, and TreeSet in java.
Differences Between HashSet, LinkedHashSet, and TreeSet:
Features
| HashSet
| LinkedHashSet
| TreeSet
|
---|
Internal Working
| HashSet internally uses HashMap for storing objects
| LinkedHashSet uses LinkedHashMap internally to store objects
| TreeSet uses TreeMap internally to store objects
|
When To Use
| If you don’t want to maintain insertion order but want to store unique objects
|