Possible Duplicate:
Java: What is the difference between implementing Comparable and Comparator?
Difference between comparable interface and comparator interface and where to use?example?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Comparablemakes an object intrinsically comparable to other objects.Comparatorallows to implement external comparison logic, which can be applied to objects that are notComparable, or that require different logic from their default comparison logic.For example, you have
Collections.sort(list), which can sort only lists of objects that implementComparable, while there is another method –Collections.sort(list, comparator), by which you can sort any list.