search
HomeJavaJavaBaseWhat is the difference between == and equals in java

What is the difference between == and equals in java

Nov 13, 2019 am 11:19 AM
==equalsjavathe difference

What is the difference between == and equals in java

== Difference between equals:

For ==:

acts on basic data For variables of type, directly compare whether the "values" they store are equal; when

acts on variables of reference type, the address of the pointed object is compared.

For equals:

The equals method cannot be applied to variables of basic data types;

If the equals method in Object is not overridden, then What is compared is the address of the object pointed to by the reference type variable, otherwise the content is compared.

Example:

String str1 = "abc";
String str2 = "abc";
String str3 = new String("abc");
String str4 = new String("abc");
当:  str1 == str2    输出:true    当:str1.equals(str2); 输出:true
当:  str1 == str3 输出:false      当:str1.equals(str3); 输出:true
当:  str3 == str4 输出:false      当:str3.equals(str4); 输出:true

Recommended tutorial:Java tutorial

The above is the detailed content of What is the difference between == and equals in java. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment