Home > Java > Javagetting Started > What are the differences between java == and equals

What are the differences between java == and equals

爱喝马黛茶的安东尼
Release: 2019-11-11 16:05:50
Original
4107 people have browsed it

What are the differences between java == and equals

To summarize:

(1) For ==, the comparison is whether the values ​​are equal;

If If it acts on a variable of a basic data type, it will directly compare whether its stored "value" is equal;

If it acts on a variable of a reference type, it will compare the address of the pointed object.

(2) For the equals method, note: the equals method cannot act on variables of basic data types. equals inherits the Object class and compares whether they are the same object;

If If the equals method is not overridden, the address of the object pointed to by the reference type variable is compared;

If classes such as String and Date override the equals method, the comparison is The contents of the pointed object.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

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