#In Java, the equals() method can be used to determine if a string is not equal. The equals() method is used to compare a string with a specified object.
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.
Example
public class Test { public static void main(String args[]) { String Str1 = new String("runoob"); String Str2 = Str1; String Str3 = new String("runoob"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str1.equals( Str3 ); System.out.println("返回值 = " + retVal ); } }
The execution result of the above program is:
Return value = true
Return value = true
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of How to determine if strings are not equal in Java. For more information, please follow other related articles on the PHP Chinese website!