Hashset - Sorting of strings
829294Jan 7 2011 — edited Jan 7 2011Hi,
I have tried the below code
public class TestSet {
public static void main(String[] args) {
HashSet<String> s=new HashSet<String>();
s.add("Z");
s.add("C");
s.add("X");
s.add("A");
s.add("B");
Iterator i=s.iterator();
while(i.hasNext()){
System.out.println((String)i.next());
}
}
}
As per API HashSet is unsorted so i should get the result ZCXAB, instead i got printed ABCXZ how come sorting is happened automatically?
Appriciate any suggestions on this?