import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class JavaTest {

// HashSet不保证集合的迭代顺序；也许在某些时间迭代的顺序与插入顺序一致，但是不保证该顺序恒久不变。
private static Set<Integer> mSetInt = new HashSet<Integer>();
private static Set<String> mSetString = new HashSet<String>();

/**
* @param args
*/
public static void main(String[] args) {

for (int i = 0; i < 50; i++) {
}

Iterator<Integer> setIntIt = mSetInt.iterator();
System.out.println("The sequence of HashSet for Integer:");
while(setIntIt.hasNext()) {
System.out.print(setIntIt.next() + " ");
}
System.out.println();

System.out.println("The sequence of HashSet for String:");
Iterator<String> setStringIt = mSetString.iterator();
while(setStringIt.hasNext()) {
System.out.print(setStringIt.next() + " ");
}
System.out.println();

System.out.println("The sequence of LinkedHashSet for Integer:");
}
System.out.println();

System.out.println("The sequence of LinkedHashSet for String:");
}
System.out.println();
}

}

The sequence of HashSet for Integer:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 34 35 32 33 38 39 36 37 42 43 40 41 46 47 44 45 49 48
The sequence of HashSet for String:
35 36 33 34 39 37 38 43 42 41 40 22 23 24 25 26 27 28 29 3 2 1 0 7 30 6 5 32 4 31 9 8 19 17 18 15 16 13 14 11 12 21 20 49 48 45 44 47 46 10
The sequence of LinkedHashSet for Integer:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
The sequence of LinkedHashSet for String:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

07-07 506

09-22 157

03-25 105

12-21 111

02-27 190

07-01 104

08-22 35