Home Tutorial Java Collections Arraylist Java arraylist sort


Share on Google+Share on Google+
Java arraylist sort
Posted on: October 23, 2009 at 12:00 AM
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]

Related Tags for Java arraylist sort:

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.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements