Caution:
The = = is NOT used with
String
variables.
Remember, String variables are
stored in memory by storing addresses to the actual string text.
If we tried to use the = = operator, we would be comparing the
addresses and not the actual string text.
To test two
String
variables (or any two objects) to see if they have equal values, you must
use the method
equals
rather than = =.
s1.equals(s2)
//checks for equality
s1.equalsIgnoreCase(s2)
//checks for equality ignoring case
|