/** * @author lautturi.com * Java example: sort an array in decreasing/descending/reverse order in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { int[] arr = { 11, 4, 2, 7, 55, 16, 12, 8, 13, 38 }; System.out.println("The original array is: "); for (int num : arr) { System.out.print(num + " "); } int[] arrDesc = Arrays.stream(arr).boxed() .sorted(Collections.reverseOrder()) .mapToInt(Integer::intValue) .toArray(); System.out.println("\nThe sorted array is: "); for (int num : arrDesc) { System.out.print(num + " "); } } }
output:
The original array is: 11 4 2 7 55 16 12 8 13 38 The sorted array is: 55 38 16 13 12 11 8 7 4 2