[Java learning notes] autoboxing and autounboxing)

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

Import Java. util. arraylist; public class autoboxing {public static void main (string [] ARGs) {// manually packed to solve the problem that the container class cannot place basic data types integer intvalue = new INTEGER (1 ); // The encapsulation class is a reference type. The stack stores references. The actual values of double doublevalue = new double (0.5) and float floatvalue = new float (1.1f) are stored on the stack ); int intvar = intvalue. intvalue (); // The basic data type is double doublevar = doublevalue that is directly stored on the stack. doublevalue (); float floatvar = floatvalue. floatvalue (); System. Out. println (intvar + "" + doublevar + "" + floatvar); arraylist <integer> arr = new arraylist <integer> (); arr. add (intvalue); arr. add (1); // automatic packaging to convert the basic data type to the packaging class. Int A = arr. get (0); // automatically unpacks integer I = 2; // automatically packs int B = I + 2; // automatically unpacks integer c = B + 2; // automatically package system. out. println (B) ;}} I noticed that in specification, if the value p being boxed is true, false, a byte, a char in the range/u0000 to/u007f, or an int or short number between-128 and 127, then let R1 and R2 bethe results of any two boxing conversions of P. it is always the case that R1 = R2. that is to say, these two values are R1 = R2. The total return value is true.

 

Author: gnuhpc

Source: http://www.cnblogs.com/gnuhpc/

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.