Automatic unpacking and packing of Basic Data Types

Source: Internet
Author: User
/*** Automatic packing: * integer num1 = 12; * Automatic unpacking: * system. out. println (num1 + 12); * Basic Data Type object cache: * integer num1 = 12; * integer num2 = 12; this is equal, and <= 127 is true * system. out. println (num1 = num2); * integer num3 = 129; this part is not equal because it is an object * integer num4 = 129; * system. out. println (num3 = num4); * integer num5 = integer. valueof (12); * integer num6 = integer. valueof (12); the principle of this piece is the same as that of * system. out. println (num5 = num6); * @ author partner4java **/public class helloworld1 {public static void main (string [] ARGs) {// within one byte (enjoy the metadata mode -- flyweight) integer int1 = 12; integer int2 = 12; system. out. println ("int1 = int2:" + (int1 = int2); // an integer other than one byte int3 = 128; integer int4 = 128; system. out. println ("int3 = int4:" + (int3 = int4); integer int5 = new INTEGER (12); integer int6 = new INTEGER (12); system. out. println ("int5 = int6:" + (int5 = int6); integer int7 = integer. valueof (12); integer int8 = integer. valueof (12); system. out. println ("int7 = int8:" + (int7 = int8); string str1 = "ABC"; string str2 = "ABC"; system. out. println ("str1 = str2:" + (str1 = str2); string str3 = new string ("ABC"); string str4 = new string ("ABC "); system. out. println ("str3 = str4:" + (str3 = str4); // background print: // int1 = int2: True // int3 = int4: false // int5 = int6: false // int7 = int8: True // str1 = str2: True // str3 = str4: false }}

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.