Package java.util

Interface Comparator<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int compare​(T lhs, T rhs)
      Compares the two specified objects to determine their relative ordering.
      boolean equals​(Object object)
      Compares this Comparator with the specified Object and indicates whether they are equal.
    • Method Detail

      • compare

        int compare​(T lhs,
                    T rhs)
        Compares the two specified objects to determine their relative ordering. The ordering implied by the return value of this method for all possible pairs of (lhs, rhs) should form an equivalence relation. This means that
        • compare(a,a) returns zero for all a
        • the sign of compare(a,b) must be the opposite of the sign of compare(b,a) for all pairs of (a,b)
        • From compare(a,b) > 0 and compare(b,c) > 0 it must follow compare(a,c) > 0 for all possible combinations of (a,b,c)
        Parameters:
        lhs - an Object.
        rhs - a second Object to compare with lhs.
        Returns:
        an integer < 0 if lhs is less than rhs, 0 if they are equal, and > 0 if lhs is greater than rhs.
        Throws:
        ClassCastException - if objects are not of the correct type.
      • equals

        boolean equals​(Object object)
        Compares this Comparator with the specified Object and indicates whether they are equal. In order to be equal, object must represent the same object as this instance using a class-specific comparison.

        A Comparator never needs to override this method, but may choose so for performance reasons.

        Overrides:
        equals in class Object
        Parameters:
        object - the Object to compare with this comparator.
        Returns:
        boolean true if specified Object is the same as this Object, and false otherwise.
        See Also:
        Object.hashCode(), Object.equals(java.lang.Object)