I just recently learned Java, and I encountered a difficult problem today when I was programming, which was about judging whether two strings are equal. In programming, the expression that usually compares whether two strings are the same is "==", but it cannot be written like this in Java. In java, equals() is used;
Example: A string and B and string comparison:
if(A.equals(B)){ }
Return true or false.
String's equals Method used to compare two strings for equality. Since string is an object type, it cannot be judged by simple "==". Use equals to compare whether the contents of two objects are equal.
Note:
equals() compares the contents of the objects (differentiating the case format of letters), but if "==" is used to compare two objects, the two objects are compared. The memory address of the object, so they are not equal. Even if their contents are equal, the memory addresses of different objects are different.
The above is the detailed content of java string comparison method. For more information, please follow other related articles on the PHP Chinese website!