Can you use == for string in Java?

In String, the == operator is used to comparing the reference of the given strings, depending on if they are referring to the same objects . When you compare two strings using == operator, it will return true if the string variables are pointing toward the same java object. Otherwise, it will return false .

Read more

Can I use == for string?

== compares the exact values. So it compares if the primitive values are the same, or if the references (addresses) are the same. That’s why == often doesn’t work on Strings ; Strings are objects, and doing == on two string variables just compares if the address is same in memory, as others have pointed out. .

Read more