Answers for "sorting arraylist in java in descending order"

2

java list sort descending

import java.util.*;
public class Details  {

	public static void main(String args[]){
	   ArrayList<String> arraylist = new ArrayList<String>();
	   arraylist.add("AA");
	   arraylist.add("ZZ");
	   arraylist.add("CC");
	   arraylist.add("FF");

	   /*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);
		}
	}
}
Posted by: Guest on December-28-2020
1

how to sort the arraylist in ascending order in java

Collections.sort(ArrayList);
Posted by: Guest on February-23-2021

Code answers related to "sorting arraylist in java in descending order"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language