Difference between HashSet, LinkedHashSet and TreeSet in Java

PropertyHashSetLinkedHashSetTreeSet
Underline Data StructureHashTableHashTable + LinkedList BalancedTree
DuplicacyNot AllowedNot AllowedNot Allowed
Insertion OrderNot Preserved PreservedNot Preserved
Sorting OrderNot ApplicableNot ApplicableApplicable
Heterogeneous ObjectAllowedAllowedNot Allowed
Null InsertionAllowedAllowedNot Allowed

Note- In TreeSet null insertion is allowed as the first element until Java 1.6v, but after 1.7v null insertion is not allowed.

Similar Java Tutorials

Leave a Comment