The difference between equals () and "= =" in Java

Source: Internet
Author: User

1. For the underlying data type, use "= =" to compare the values for equality;

2. For composite data types (classes), the Equals () and "= =" effects are the same, both of which are compared to the storage address of the object in memory (specifically, the heap memory address).

3. For a type that overrides the Equals () method for string, Integer, date, and so on, "= =" compares the stored memory address. The result of equals () is determined by the overwritten code.

In the 4.string type, equals () compares two strings for the same content. Such as:

String S1 = "Hello"; String s2 = "Hello"; s1.equals (s2) returns TRUE;S1==S2 returns true;string S1 = "Hello"; String s2 = new String ("Hello"), s1.equals (S2) returns true, but S1==s2 returns false;

  

The difference between equals () and "= =" in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.