Sorting a List : Collections Sort « Collections « Java Tutorial






import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class MainClass {
  public static void main(String args[]) throws Exception {
    List list = Arrays.asList("a","c","b");
    Collections.sort(list);
    for (int i = 0, n = list.size(); i < n; i++) {
      if (i != 0)
        System.out.print(", ");
      System.out.print(list.get(i));
    }
    System.out.println();
  }
}
a, b, c








9.42.Collections Sort
9.42.1.Sorting a List
9.42.2.Reversing Order
9.42.3.Sorting a Collection containing user defined Objects
9.42.4.Keeping upper and lowercase letters together