Collections.reverseOrder()
See Example:
import java.util.ArrayList;
import java.util.Collections;
public class SortArrayDescending {
public static void main(String args[]){
ArrayList<String> arrlist = getArrayList();
}
public static ArrayList<String> getArrayList(){
ArrayList<String> arraylist = new ArrayList<String>();
arraylist.add("Apple");
arraylist.add("Orange");
arraylist.add("Coconut");
arraylist.add("Mango");
/*Unsorted List: ArrayList content before sorting*/
System.out.println("Before Sorting:");
for(String str: arraylist){
System.out.println(str);
}
/* Sorting in decreasing order*/
Collections.sort(arraylist, Collections.reverseOrder());
/* Sorted List in reverse order*/
System.out.println("ArrayList in descending order:");
for(String str: arraylist){
System.out.println(str);
}
return arraylist;
}
}
//result
Before Sorting:
Apple
Orange
Coconut
Mango
ArrayList in descending order:
Orange
Mango
Coconut
Apple
EmoticonEmoticon