🎙 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 6 of 13

Why is (a, b) - a - b a risky Java comparator?

Why is (a, b) -> a - b a risky Java comparator?

  1. A.It sorts in descending order
  2. B.It is not allowed in lambdas
  3. C.The subtraction can overflow for large values and give the wrong sign
  4. D.It makes the sort unstable
Answer & explanation

Correct answer: The subtraction can overflow for large values and give the wrong sign

For values near ±2·10⁹ the difference doesn't fit in an int; Integer.compare avoids this.

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 →