Used for comparing compare two objects.

Shallow Comparison(default): Checks if two references refer to the same Object.

Deep Comparison: The data members are compared.

Most classes should override the equals for a deep comparison.

The equals() method should follow these rules.

  1. Reflexive: x.equals(x) should return true.
  2. Symmetric: x.equals(y) should return true iff y.equals(x) returns true.
  3. Transitive: If x.equals(y) returns true and if y.equals(z) returns true, then x.equals(z) should return true.
  4. Consistent: Multiple invocations of x.equals(y) should consistently return true or false if  no information in equals comparison is modified.
  5. x.equals(null) should return false.