hash set does not guarantees the order of iteration

on the other hand adding an elemnet to TreeSet is O(log n) but HashSet is O(1) (Constant time)

how is it possible to have a sorted hash set ?

if you want to be able to iterate through the set in ascending order, try

Set sortedSet= new TreeSet( yourHashSet );