1. When
you iterate through a HashSet the order is unpredictable, while a
LinkedHashSet lets you iterate through the elements in the order in
which they were inserted, TreeSet is maintaining the Sorting order
2. HashSet and LinkedHashSet uses equals() method for comparison where
as TreeSet uses compareTo() method
3. HashSet
and LinkedHashSet allows null values but TreeSet doesn't allow null
values
4. HashSet
and LinkedHashSet offers constant time performance for the basic
operations (add, remove, contains and size). TreeSet guarantees
log(n) time cost for the basic operations (add, remove and contains)
5.HashSet
implemented using hash table, LinkedHashSet is an ordered version of
HashSet that maintains a doubly-linked List across all elements and
TreeSet implemented using a tree structure like red-black tree.
No comments:
Post a Comment