I recently learned Java, and today I'm programming with a tricky question about judging whether two strings are equal. In programming, expressions that typically compare two strings for the same expression are "= =", but cannot be written in Java. In Java, Equals () is used;
Example: A string and B and string comparison:
if (A.equals (B)) {
}
Returns TRUE or FALSE.
The Equals method of a string is used to compare two strings for equality. Because the string is an object type, it cannot be judged by a simple "= =". Instead, use equals to compare the contents of two objects for equality.
Attention:
Equals () compares the contents of the object (which distinguishes the case of letters), but is not equal if you compare two objects with "= =", compared to the memory addresses of two objects. Even though their contents are equal, the memory addresses of different objects are not the same.
Java string comparison