Programming Languages
Java
Subjective
Sep 24, 2025
What is the difference between Comparable and Comparator interfaces?
Detailed Explanation
Comparable: Used for natural ordering, implemented by the class itself, has compareTo() method, provides single sorting sequence. Comparator: Used for custom ordering, implemented separately, has compare() method, provides multiple sorting sequences. Example: String implements Comparable for alphabetical sorting, but you can create Comparator for length-based sorting.
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts