Home > DeveloperSection > Interviews > What is the difference between Comparable and Comparator?

Posted on    May-13-2015 12:04 AM

 Java Java  Collection 
 1 Answer(s)
  536  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    May-13-2015 12:04 AM

1) Comparable provides only one sort of sequence.
2) It provides one method named compareTo().
3) It is found in java.lang package.
4) If we implement Comparable interface, actual class is modified.

1)    Comparator provides multiple sort of sequences.
2)    It provides one method named compare().
3)    it is found in java.util package.
4)    Actual class is not modified.

Modified On May-13-2015 12:04:56 AM

Don't want to miss updates? Please click the below button!

Follow MindStick