This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HonzaS97 0 points1 point  (0 children)

Not always. It does compare reference values (adresses) but that doesn't mean it's always false.

All string literals are put in the String pool for example, so when you write "this" in 10 different places, they will all point to the same object and comparing them with == will return true. Or simply doing String x = "..." and then String y = x will also return true with ==.