Question
In Java, which comparison about Comparable vs Comparator is accurate?
- There is no practical difference in behavior, performance, or API design when Comparable vs Comparator is involved.
- Use Comparable for one stable default order and Comparator for multiple business-specific sorting rules.
- The oldest option related to Comparable vs Comparator is always the right production choice regardless of context.
- Differences around Comparable vs Comparator are mostly cosmetic, so correctness and maintainability do not change.
Hint
Focus on the behavior or tradeoff, not just the keyword.
Answer and rationale
Correct answer: B. Use Comparable for one stable default order and Comparator for multiple business-specific sorting rules.
Use Comparable for one stable default order and Comparator for multiple business-specific sorting rules. This is the comparison that usually separates memorization from understanding.
Track: Java