search
HomeJavaJavaBaseJava uses if statement to determine whether strings are equal

Java uses if statement to determine whether strings are equal

String comparison in Java cannot directly use "==", but must use equals(). Return true if the two strings are equal, and return false if the two strings are not equal. For example: (Recommended learning: java video tutorial)

if (s1.equals(s2)) {
 System.out.println("s1与s2相等!!");
} else {
 System.out.println("s1与s2没啥关系!!");
}

1. String is an object type, so it cannot be judged by simple "==";

2. Equals() compares whether the contents of the objects (in the case-sensitive format of letters) are equal;

3. When "==" compares two objects, it compares the contents of the two objects. memory addresses, so they are not equal.

Recommended related articles and tutorials: java introductory tutorial

The above is the detailed content of Java uses if statement 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool