← All Exercises
Java Array Sorting
basicjava
Background
Java provides built-in sorting algorithms in Arrays and Collections with O(n log n) performance.
Problem
Write a Java method that takes an int array and returns a new sorted array in descending order using Integer wrapper and comparator.
Input
An array of integers.
Output
A new array sorted in descending order.
Sample tests
Sample 1
Input: [5, 2, 8, 1, 9, 3]
Expected: [9, 8, 5, 3, 2, 1]
Your solution
Learning objective
Learn Arrays.sort, Collections.reverseOrder, and primitive vs wrapper type sorting.