Use TreeSet to sort random numbers : TreeSet « Utility Classes « SCJP






import java.util.Iterator;
import java.util.TreeSet;

public class MainClass {
  public static void main(String[] argv) {
    TreeSet set = new TreeSet();
    for (int i = 0; i < 3; i++)
      set.add(Math.random());

    Iterator iter = set.iterator();
    while (iter.hasNext())
      System.out.println(iter.next());

  }
}
0.21972875445139584
0.27062139982567435
0.9615419196391383








8.17.TreeSet
8.17.1.An Iterator from TreeSet presents elements in some kind of sorted order.
8.17.2.The TreeSet class implements the java.util.SortedSet interface, which extends java.util.Set.
8.17.3.Use TreeSet to sort random numbers
8.17.4.Navigating (Searching) TreeSets and TreeMaps