Java basic type and package type

Source: Internet
Author: User

1, basic type and basic type of package for the "= =" operator comparison, the basic package type will automatically remove the box into the basic type and then compare, so the integer (0) will automatically unboxing to the int type and then compare, obviously return true;
2, two integer type "= =" comparison, if its value is 128 to 127, then return True, otherwise return false, this is related to the buffer object of integer.valueof (), here does not repeat.
3, two basic type of package for equals () comparison, first equals () will compare the type, if the type is the same, continue to compare the value, if the value is the same, return True
4, the basic package type calls Equals (), but the parameter is the basic type, this time, the first automatic boxing, the basic type conversion to its package type, and then the comparison in 3.

int A=257;integer B=257;integer C=257;integer b2=57;integer c2=57; System.out.println (a==b);//true//system.out.println (A.equals (b));  Compile error, basic type cannot call Equals () System.out.println (B.equals (257.0));//flasesystem.out.println (b==c);// FalseSystem.out.println (B2==C2);//true

Java basic type and package type

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.