How to override compareTo (Java)
As I see you have wrong implementation of compare method. Could you update it to?
As I see you have wrong implementation of compare method. Could you update it to?
When your class implements Comparable, the compareTo method of the class is defining the “natural” ordering of that object. That method is contractually obligated (though not demanded) to be in line with other methods on that object, such as a 0 should always be returned for objects when the .equals() comparisons return true. A Comparator is its own definition of how to … Read more