Professional Documents
Culture Documents
.equals() method compares the values and returns the result accordingly. If we
modify the above code with -
System.out.println(str1.equals(str2));
Then it returns true.
equals() ==
This is a method defined in the Object class. It is a binary operator in Java.
The .equals() Method is present in the Object class, so we can override our
custom .equals() method in the custom class, for objects comparison. It cannot be
modified. They always compare the HashCode.
This method is used for checking the equality of contents between two objects as
per the specified business logic. This operator is used for comparing addresses
(or references), i.e checks if both the objects are pointing to the same memory
location.