Write a program to Sort Numeric Array In Descending Order


This program sorts an array of integers in descending order using the Arrays.sort() method and the Collections.reverseOrder() method.

The Arrays.sort() method is used to sort the array in ascending order. The Collections.reverseOrder() method is then used to reverse the order of the sorted array, resulting in a descending order sorting.

The program first initializes an array of integers, and then prints the original array. It then sorts the array in descending order using Arrays.sort() and Collections.reverseOrder(), and prints the sorted array.

Source Code

import java.util.Arrays;
import java.util.Collections; 
public class Descending 
{ 
    public static void main(String[] args) 
    {
		Integer[] arr = {23,5,67,20,3,30,79,3,70,2}; 
		System.out.println("Original Array : "+Arrays.toString(arr));
		Arrays.sort(arr, Collections.reverseOrder());
		System.out.println("Sorted Array : "+Arrays.toString(arr)); 
    } 
}

Output

Original Array : [23, 5, 67, 20, 3, 30, 79, 3, 70, 2]
Sorted Array : [79, 70, 67, 30, 23, 20, 5, 3, 3, 2]

Example Programs