Theprevious tutorialwas all about sorting an array in ascending order. In this post we are going to learn how to sort an array inDescending (Reverse) Order. Example Here we have two arrays, one is integer array
In one of the previous examples, we covered how to sort an ArrayList in ascending order. In this post, you will learn how to sort ArrayList in descending order in Java. We will explore the following ways: Using the sort() method Using the Collections.sort() and Collections.reverse() ...
// C# program to implement bubble to sort an array// in descending order.usingSystem;classSort{staticvoidBubbleSort(refint[] intArr) {inttemp =0;intpass =0;intloop =0;for(pass =0; pass <= intArr.Length -2; pass++) {for(loop =0; loop <= intArr.Length -2; loop++) {if(int...
Thereverse()method reverses the elements in an array: Example constfruits = ["Banana","Orange","Apple","Mango"]; fruits.reverse(); Try it Yourself » By combiningsort()andreverse(), you can sort an array in descending order:
2.1. Ascending Order Java program to sort an array of integers in ascending order usingArrays.sort()method. //Unsorted arrayInteger[]numbers=newInteger[]{15,11,...};//Sort the arrayArrays.sort(numbers); 2.2. Descending Order Java providesCollections.reverseOrder()comparatorto reverse the defaul...
/*Java Program to Sort an Array in Descending Order*/ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n; //Array Size Declaration System.out.println("Enter the number of elements :"); ...
// Swift program to sort an integer array// in descending orderimport Swift var arr:[Int]=[12,10,25,20,50] print("Original array: ",arr) arr.sort() arr.reverse() print("Sorted array: ",arr) Output: Original array: [12, 10, 25, 20, 50] Sorted array: [50, 25, 20, 12, ...
C Program to Sort N Numbers in Ascending Order using Bubble Sort C program to sort integers using Bubble Sort C Program to Sort N Names in an Alphabetical Order Java Program to Sort an Array in Descending Order C Program to Sort the Array Elements using Gnome Sort C Program to Sor...
vals.sort(Comparator.reverseOrder()); System.out.println(vals); } The integers are sorted in ascending and descending orders. The data is sorted in-place; i.e. the original list is modified. $ java Main.java [-4, -2, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8] ...
aabzABZ , if sort_order = " asc " (ascending sort)- ZBAzbaa, if sort_order = "desc" (descending sort) textnocase : sorts text alphabetically, without regard to case (also known as case-insensitive). A letter in varying cases precedes the next letter: aAaBbBzzZ, in an ascending ...