Question: what is the difference between hashset linkedhashset and treeset?
Answer: HashSet: If you don't want to maintain insertion order but want store unique objects. LinkedHashSet: If you want to maintain insertion order of elements then you can use LinkedHashSet. TreeSet: If you want to sort the elements according to some Comparator then use TreeSet.