Como comparar dos variables de tipo String en java?. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

Como comparar dos variables de tipo String en java?.

Si comparo dos String con el mismo texto mediante == porque no me da true?

28th Sep 2017, 1:21 PM
Luis Gerardo Collazos Castro
Luis Gerardo Collazos Castro - avatar
1 Resposta
+ 13
The "=="Ā operator compares the value ofĀ two object referencesĀ to see whether they refer to the sameĀ String instance while the equals()Ā methodĀ compares the "value" inside String instances (on the heap) irrespective of the two object references refer to the same String instance or not. P.S. That's the reason why "==" resulted in false! You should use the equals() method when comparing two Strings.
28th Sep 2017, 1:47 PM
Dev
Dev - avatar