Comparable and Comparator interfaces are used for object comparison in Java programs. When using collection classes like TreeSet or TreeMap, both of these interfaces can be used to provide sorting order to objects.

Though java.util package contains these two interfaces, but the difference between the two lies in their purpose. The following table shows the difference between two interfaces:

Comparable Comparator
Purpose:
Comparable interface is used to provide sorting order to the current class’s object implicitly.
Purpose:
Comparator interface is used to provide sorting order to two objects passed as argument to its methods.
Implementation method:
There is a method named public int compareTo(Object o) declared in this interface.
Implementation method:
There is a method named public int compare(Object o1, Object o2) declared in this interface.
When to use:
Use of this interface is recommended when access to the source code of class is available.
When to use:
Use of this interface is recommended when the access to the source code of class is not available. For example when compairing objects of a class present in JAR file.
JDK implementation:
java.lang.String and all wrapper classes are example classes implementing the comparable interface.
JDK implementation:
java.text.Collator is example interface implementing the comparator interface.
Sorting:
Comparable is used to provide natural sorting order.
Sorting:
Comparator is used to provide an order other than the natural sorting order.
Sample code:

public class Test implements Comparable<String>{

    String a;

    public int compareTo(String o) {
        return this.a.compareTo(o);
    };
}
Sample code:

import java.util.Comparator;

public class Test implements Comparator<Test>{

    String a;

    public int compare(Test o1,Test o2) {
        return o1.a.compareTo(o2.a);
    };
}
Difference between Comparable and Comparator interfaces admin Core Java
Comparable and Comparator interfaces are used for object comparison in Java programs. When using collection classes like TreeSet or TreeMap, both of these interfaces can be used to provide sorting order to objects. Though java.util package contains these two interfaces, but the difference between the two lies in their purpose....
<a href="http://www.javaexperience.com/overriding-compareto-method-in-java/">Comparable</a> and Comparator <a href="http://www.javaexperience.com/exhaustive-differences-between-abstract-class-and-interface/">interfaces</a> are used for object comparison in Java programs. When using collection classes like <a href="http://www.javaexperience.com/difference-between-treemap-and-treeset-in-java/">TreeSet or TreeMap</a>, both of these interfaces can be used to provide sorting order to objects. Though java.util package contains these two interfaces, but the difference between the two lies in their purpose. The following table shows the difference between two interfaces: <table> <thead> <th><a href="http://www.javaexperience.com/overriding-compareto-method-in-java/">Comparable</a></th> <th><a href="http://www.javaexperience.com/compare-objects-using-comparator-in-java/">Comparator</a></th> </thead> <tbody> <tr> <td><strong>Purpose:</strong><br/> Comparable interface is used to provide sorting order to the current class's object implicitly.</td> <td><strong>Purpose:</strong><br/> Comparator interface is used to provide sorting order to two objects passed as argument to its methods.</td> </tr> <tr> <td><strong>Implementation method:</strong><br/> There is a method named public int compareTo(Object o) declared in this interface.</td> <td><strong>Implementation method:</strong><br/> There is a method named public int compare(Object o1, Object o2) declared in this interface.</td> </tr> <tr> <td><strong>When to use:</strong><br/> Use of this interface is recommended when access to the source code of class is available.</td> <td><strong>When to use:</strong><br/> Use of this interface is recommended when the access to the source code of class is not available. For example when compairing objects of a class present in JAR file.</td> </tr> <tr> <td><strong>JDK implementation:</strong><br/> java.lang.String and all wrapper classes are example classes implementing the comparable interface.</td> <td><strong>JDK implementation:</strong><br/> java.text.Collator is example interface implementing the comparator interface.</td> </tr> </tr> <tr> <td><strong>Sorting:</strong><br/> Comparable is used to provide natural sorting order.</td> <td><strong>Sorting:</strong><br/> Comparator is used to provide an order other than the natural sorting order.</td> </tr> <tr> <td><strong>Sample code:</strong><br/> 1 </td> <td><strong>Sample code:</strong><br/> 1 </td> </tr> </tbody> </table>