What is the difference between `HashSet` and `TreeSet` in Java?
`HashSet` does not allow duplicate elements, and `TreeSet` stores elements in sorted order.
You're on the right track! Both `HashSet` and `TreeSet` don't allow duplicates, but `TreeSet` specifically ensures the elements are sorted.
Can you explain how the sorting works in `TreeSet` when a custom comparator is provided?