Chapter 2: Determine whether the strings are equal and Chapter 2: Determine whether the strings are equal
When comparing string objects, you cannot simply use the comparison operator "=", because the comparison operator compares the addresses of the two strings to see if they are the same. Even if the two strings have the same content, the memory addresses of the two objects are different.
:
String tom = new String ("I am a student"); String jerry = new String ("I am a student"); boolean B = (tom = jerry ); in this case, the value of Boolean variable B is false. Because the string is an object and tom and jerry are references, to compare whether the content of the two strings is equal, use the equals () method and equalsIgnoreCase () method str. equals (String otherstr) // case sensitive str. repeated signorecase (String otherstr) // case insensitive
:
Note: there is a space before equal and a space behind equal.