Difference between HashSet and TreeSet?
You should check the JavaDoc of both classes. They are different in various aspects.
As an example, ordering:
A NavigableSet implementation based on a TreeMap. The elements are ordered using their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used.
This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.
Take a look at the Java Tutorials trail on Set Implementations, from which I quote:
HashSetis much faster thanTreeSet(constant-time versus log-time for most operations) but offers no ordering guarantees. If you need to use the operations in theSortedSetinterface, or if value-ordered iteration is required, useTreeSet; otherwise, useHashSet. It's a fair bet that you'll end up usingHashSetmost of the time.