Knowledge Walls
John Peter
Pune, Maharashtra, India
Sort an Arraylist in Ascending and Descending order example with JAVA
3968 Views
ListSorting
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListSorting {
    public static void main(String args[]){
        List<String> dataList = new ArrayList<String>();
            dataList.add("Ball");
            dataList.add("Apple");
            dataList.add("Dog");
            dataList.add("Cat");
            
        //Ascending order of List of Strings
        Collections.sort(dataList);
        System.out.println("Ascending Order");
        System.out.println(dataList);
        
        //Descending order of List of Strings
        Collections.sort(dataList,Collections.reverseOrder());
        System.out.println("Decending Order");
        System.out.println(dataList);
    }
}
Output 
Next Topics
Next lessons of current book.
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details