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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Utility Classes » TreeSet 
8.17.3.Use TreeSet to sort random numbers
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.