+ 4
How the result of the code is true explain
The following was the challenge of sololearn quiz factory. The output of the code was true. Can someone explain me why the output is true as generally while comparing strings we use dot equals method. https://code.sololearn.com/cC3i0HIpoSOo/?ref=app
7 Respuestas
+ 9
although you have created 2 strings with different variables in string pool there is only one string created called "a" both variables a and b refer to the same object "a" so a==b results in being true
+ 9
== ⬅compares refreneces of both objects if you create a string using the new keyword and one without but both strings being the same then this would result in false becuase they have diffrent memory addresses.
+ 5
D_Stark Thanks for u help.really it helped
+ 3
Then y do we use equals method
+ 3
D_Stark ??
0
Equals method verify if it's true or not it does not give you Boolean value
0
Variable a and variable b both store the string value "a".
When comparing, I find "a" (stored in a) and "a" (stored in b) to be equivalent.
Hence checking for equivalence would return true.