talking about = = and equals

Source: Internet
Author: User

I've never done much research on these two rules of comparison, the confused know how to compare, also has not made mistakes, a moment to make dizzy, whistling, suddenly like research,

Simply:

= = is a comparison of two object addresses, focusing on the comparison of value objects, the comparison of values with equals comparison value Reference object its comparison results must be correct, but not recommended to use, appear irregular bar

The actual value reference is stored in the stack, each value is unique in the stack, the address in the stack is unique, the comparison is the address value, so if the value of two or more reference objects is the same, it points to the stack of the

The value address must be the same

According to the continuation analysis above, equals is the same as the content stored in the stack of two or more objects compared, not the same as the stack address, each class object will have a comparison of the Equals method, but there is an override for equals in the String class. So focusing on the equals of the string object, it's important to note

Drawing a schematic reference, look at the following example:

Qus result

I1==i2 false

I1.equals (I2) True

I2==i3 false

I2.equals (i3) False

I3 ==i4 True

I3.equals (I4) false

Thank you for reading, if there are errors please criticize correct, I will be open-minded to accept, learn from each other!!!

Thanks again!!!

talking about = = 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.