Overriding equals() needed when we compare references.
if we compare String reference, why do we not need overriding equals?
question on equals() method
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
10 February 2020, 15:15solution
The .equals() method for the String class compares the actual value stored in the variables as opposed to object references. Below is some simple code to show how using the '==' operator can give incorrect results. The code takes 4 string variables, all holding the value "test", and compares them against the first one. You will see that it will results false on one of the Boolean checks even though they are all the same.
+2
Ashish RajAnand
11 February 2020, 07:08
thanks alot
0