Home  >  Article  >  Java  >  Java uses if to determine whether strings are equal

Java uses if to determine whether strings are equal

尚
Original
2019-12-24 15:47:513582browse

Java uses if to determine whether strings are equal

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn