In Java, the == operator compares that two references are identical or not . Whereas the equals() method compares two objects. Objects are equal when they have the same state (usually comparing variables). Objects are identical when they share the class identity.
Read moreHow do you compareTo objects in Java?
The compareTo method defines the natural order; the default way for ordering objects of a class. It should return a negative integer(usually -1), if the current triggering object is less than the passed one, and positive integer (usually +1) if greater than, and 0 if equal.
Read moreHow does compareTo method compare objects in Java?
The compareTo method compares the current object with the object sent as a parameter . When implementing it, we need to make sure that the method returns: A positive integer, if the current object is greater than the parameter object. A negative integer, if the current object is less than the parameter object.
Read more