← Quiz: Counting Sort and Custom Sorting: all 13 questions
Quiz: Counting Sort and Custom Sorting · Question 7 of 13
Which line sorts an Integer[] nums in descending order in Java?
Which line sorts an Integer[] nums in descending order in Java?
- A.Arrays.sort(nums, -1);
- B.Arrays.sort(nums, Collections.reverseOrder());
- C.Collections.sort(nums).reverse();
- D.nums.sortDescending();
Answer & explanation
Correct answer: Arrays.sort(nums, Collections.reverseOrder());
Collections.reverseOrder() is a comparator for objects such as Integer; it doesn't work with int[].
Can you get the rest right without peeking?
Take the timed Quiz: Counting Sort and Custom Sorting quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →