Sorting Collections and Arrays : Collections « Utility Classes « SCJP






import java.util.ArrayList;
import java.util.Collections;

public class MainClass {
  public static void main(String[] args) {
    ArrayList<String> stuff = new ArrayList<String>(); // #1
    stuff.add("A");
    stuff.add("B");
    stuff.add("D");
    stuff.add("A");
    stuff.add("W");
    System.out.println("unsorted " + stuff);
    Collections.sort(stuff); // #2
    System.out.println("sorted   " + stuff);
  }
}
unsorted [A, B, D, A, W]
sorted   [A, A, B, D, W]








8.12.Collections
8.12.1.Java Collections
8.12.2.Make List a Thread-Safe Class
8.12.3.Sorting Collections and Arrays
8.12.4.Return a reference to a new Map that accesses the existing data but with synchronized methods