What is the difference between HashSet and TreeSet in Java?

  HashSet TreeSet
1. Offers constant time cost Offers log time cost
2. Does not maintain the order of elements By default sorts elements in ascending order.
3. Implemented using a hash table Implemented using Binary Search Tree

Suggest An Answer

No suggestions avaliable!

Related Interview Questions