How do I compare strings in Java?

== tests for reference equality.
.equals() tests for value equality.
Consequently, if you actually want to test whether two strings have the same value we should use .equals().

Comments