Don't confuse the equals method with the equality operator (==).
If you try to compare two strings like this:
if str == str2
System.out.println ("true");
else
System.out.println ("false");
you are actually checking to see whether the two references str and
str2 refer to the same object. It is possible that two strings are equal
without them being the same object. So if you want to compare the
contents of the string use equal, if you want to check if the two
references refer to the same object use ==. Two references which
point to the same object will always return true with the equals
method, but two references which refer to different objects, both
containing the same string, with be false with the == operator.