Java uses if method to determine whether strings are equal:
public class TestCode { public static void main(String [] args){ String a = "abcdb"; String b = "bcddeb"; if(!a.equals(b)){ System.out.print("a不等于b"); }else{ System.out.print("a等于b"); } } }
equals() method is used to compare strings with specified objects.
Syntax
public boolean equals(Object anObject)
Parameters
anObject -- The object to compare with the string.
Return value
Returns true if the given object is equal to the string; otherwise returns false.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java uses if to determine whether strings are equal. For more information, please follow other related articles on the PHP Chinese website!