Home > Java > JavaBase > body text

Java uses if to determine whether strings are equal

Release: 2019-12-24 15:47:51
Original
3570 people have browsed it

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");
}
}
}
Copy after login

equals() method is used to compare strings with specified objects.

Syntax

public boolean equals(Object anObject)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template