🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Arrays.sort(nums, -1);
  2. B.Arrays.sort(nums, Collections.reverseOrder());
  3. C.Collections.sort(nums).reverse();
  4. 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 →