Possible Duplicates:
String comparison and String interning in Java
What is the difference between .Equals and ==
Just a simple question about comparing strings. Why should i be using string.equals(string2) and not string==string2 ? Thank you
Possible Duplicates:
String comparison and String interning in Java
What is the difference between .Equals and ==
Just a simple question about comparing strings. Why should i be using string.equals(string2) and not string==string2 ? Thank you
equals
tests if the strings' content is the same; ==
tests if both are the same object.
In case you have two different String
objects that have the same value.
string==string2 is physical comparison and compares the references to objects. equals is logical comparison and the equality can be defined in equals() method which objects inherit this from Object (Parent of all types)