HashSet vs TreeSet:
1- Hashset gives better performance (faster) than Treeset for the operations like add, remove, contains, size etc. HashSet offers constant time cost while TreeSet offers log(n) time cost for such operations.
2- HashSet does not maintain any order of elements while TreeSet elements are sorted in ascending order by default.
Similarities:
1- Both HashSet and TreeSet does not hold duplicate elements, which means both of these are duplicate free.
2- If you want a sorted Set then it is better to add elements to HashSet and then convert it into treeset rather than creating a TreeSet and adding elements to it.