The difference between = = and equals

Source: Internet
Author: User

Today with the development to fix a bug, now list out the comparison of this detour

Scenario One:

Long a = 1;

Long B = 1;

Boolean result = (A = = B); The value of result at this time is false

Boolean result2 = (a.equals (b));//This time the value of RESULT2 is True

Boolean RESULT3 = (a.longvalue () = = B.longvalue ()); The value of RESULT3 is true at this time

Scenario Two:

Long C = 2;

Long d = 2;

Boolean result = (c = = d); The value of result is true at this time

Boolean result2 = (C.equals (d)); The value of RESULT2 at this time is true

Extension of String and StringBuilder

String occupies the stack space, each assignment will open up a new space; StringBuilder is an object that occupies the same space in the heap.

The difference between = = and equals

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.