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.
- Reflexive: x.equals(x) should return true.
- Symmetric: x.equals(y) should return true iff y.equals(x) returns true.
- Transitive: If x.equals(y) returns true and if y.equals(z) returns true, then x.equals(z) should return true.
- Consistent: Multiple invocations of x.equals(y) should consistently return true or false if no information in equals comparison is modified.
- x.equals(null) should return false.