Difference between HashSet and TreeSet in Java

Difference between HashSet and TreeSet can be seen below:

HashSet TreeSet
Inserted elements are in random order Maintains the elements in the sorted order
Can able to store null objects Couldn’t store null objects
Performance is fast Performance is slow

Top 50+ Java Interview Questions with Answers

We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates.  Q.1- What is… Read More

4 years ago