Answers for "sort list in reverse java"

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
6

how to reverse a list in java

List<String> stringList = Arrays.asList("A", "B", "C");
    Collections.reverse(stringList);
    assertThat(stringList).containsExactly("C", "B", "A");
Posted by: Guest on March-19-2020
1

reverse array java

// reverse array

for(int i=intArray.length-1;i>=0;i--)
         System.out.print(intArray[i] + "  ");
Posted by: Guest on November-23-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language