when we compare String each others.... suppose we have declared two String variables when to use a.equal(b) and (a==b) ????? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

when we compare String each others.... suppose we have declared two String variables when to use a.equal(b) and (a==b) ?????

1st Mar 2022, 7:35 AM
Davinder Kumar
Davinder Kumar - avatar
2 Respuestas
+ 3
Use of .equal() method is the preferable way opposed to use of == operator whenever a comparison of content was the goal. The == operator checks whether the two String shares the same reference, not content.
1st Mar 2022, 7:49 AM
Ipang