What do the return values of Comparable.compareTo mean in Java?
问题 What is the difference between returning 0 , returning 1 and returning -1 in compareTo() in Java? 回答1: Official Definition From the reference docs of Comparable.compareTo(T): Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must