← 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?
- A.It sorts in descending order
- B.It is not allowed in lambdas
- C.The subtraction can overflow for large values and give the wrong sign
- 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 →