The pros, cons, and alternatives of equals() in java are:
Advantages of using equals()
- This is used for testing whether one object is equal to another or not.
- Equals is defined in the object class, from which all other classes are derived, it is automatically defined for every class.
- It has been defined in a meaningful way for most Java core classes.
Disadvantages of using equals()
- It doesn’t perform an intelligent comparison for most classes’ uncles the class overrides it.
- If it is not defined for a class (user), it behaves the same as ==.
- It is hard to get the right answer in the case of subclasses.
Alternative for equality in java is:
- Java string equalsIgnoreCase() method.
- Using if-else statement.


