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 |
0 Comments