Share on Google+Share on Google+

Java arraylist sort

This Java Tutorial section we demonstrates how to use the sort() method in the Java ArrayList.

  • ArrayList doesn't have sort() method.
  • We can use the static sort  method of the Collections class
  • It sorts the given Collection object.

Example of Java Arraylist Sort
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class List1 {
    public static void main(String[] args) {
     Integer ar[]={444,222,333,111};
     ArrayList list=new ArrayList();
     System.out.println("Withiout sorting "+list);
     System.out.println("After sorting "+list);

Withiout sorting [444, 222, 333, 111]
After sorting [111, 222, 333, 444]


Posted on: October 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.