The difference between equals and = = in Java

Source: Internet
Author: User

In the project, find trial = = To compare two uuid, always false, change to. Equals, returns True.

The original = = comparison is memory address, more for the comparison of value types

Information about the type of value attached

Four categories: 1, Integer 2, float type 3, character 4, logic type

Eight kinds:
1, integral type 3 kinds of Byte,short,int,long

2, Float type 2 kinds of float,double

3, character type 1 char

4, Logic type 1 Boolean

And the UUID is not a value type, we take = = to compare the address, of course always return false.

At this point, try. Equals to compare the data pointed to by the memory and return the correct comparison results.

conclusion, if it is a value type, use = =, if it is not a value type, it is used. equals

The difference between equals and = = in Java

Related Article

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.