Based on my previous posts related to Comparator and Comparable let’s see the difference.

Comparable Comparator
Should be used when sorting with one element only Should be used when sorting with multiple elements
Need to implement compareTo(Obj ob) Need to implement compare(Obj e1, Obj e2)
Found in java.lang package Found in java.util package
Actual class is not modified. Actual class is modified.
Compares “this” reference with the object specified Compares two objects provided to compare
Categories: JAVA

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *