// exporting data from a HashSet and sorting it.
HashSet<String> h = ...;

final String[] exported = h.toArray( new String[ h.size ]  );
Arrays.sort( exported );
for ( String elt : exported )
  {
  out.println( elt );
  }