🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Comparable vs Comparator: all 10 questions

Quiz: Comparable vs Comparator · Question 6 of 10

comparing(Student::name).thenComparing(Student::marks).reversed() sorts by:

comparing(Student::name).thenComparing(Student::marks).reversed() sorts by:

  1. A.name ascending, then marks descending
  2. B.name descending, then marks ascending
  3. C.name descending, then marks descending
  4. D.marks descending only
Answer & explanation

Correct answer: name descending, then marks descending

reversed() flips the whole comparator built so far, so both keys are reversed.

Can you get the rest right without peeking?

Take the timed Quiz: Comparable vs Comparator quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →