HashSet doesnt guarentee sorting?
<pre><code>import java.util.*;
public class DuplicateCheckMain {
 public static void main(String[] gopal){
  Integer[] args = {6,9,2,55,100,1,6,8,9};
  Integer[] args1 = {3,6,2,3,5};
  Set S = new HashSet();
  DuplicateCheck.checkDuplicate(S,args,new String("HashSet"));
  Set S1 = new HashSet();
  DuplicateCheck.checkDuplicate(S1,args1,new String("HashSet"));

  S = new TreeSet();
  DuplicateCheck.checkDuplicate(S,args,new String("TreeSet"));

  S = new LinkedHashSet();
  DuplicateCheck.checkDuplicate(S,args,new String("LinkedHashSet"));

 }
}

public class DuplicateCheck {

 public static void checkDuplicate(Set S, Integer[] args, String setname){
  for(int i = 0;i&lt;args.length;i++){
   if(!S.add(args[i])){System.out.println("Duplicate element "+args[i]);}
  }
  System.out.println(S +" "+ setname);
 }
}
</code></pre>

<p>Question: for the HashSet with reference S, the HashSet is not sorted. But for the reference S1, the HashSet is sorted. Why so?</p>
