Java: Sort using Collections

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


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();
  }
}





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.