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!