Java basic type wrapper class with automatic package unpacking

Source: Internet
Author: User

A basic type wrapper class

The underlying data type is stored in the stack area of the memory, and you can convert the underlying data type to a reference data type by wrapping the class, that is, in the heap and stack.

There are 8 kinds of basic data types, and there are 8 kinds of packaging classes. Byte,short,integer,long,float,double,character,boolean, respectively. Class

The wrapper class is in Java. In the Lang packet.

1  Public classTest1 {2 3      Public Static voidMain (string[] args) {4         //TODO auto-generated Method Stub5Integer i=NewInteger (5);6Integer i2=NewInteger ("23");7Integer i3=integer.valueof (3);8Integer i4=integer.valueof ("567");9 Ten         intA=I.intvalue (); One         floatf=I.floatvalue (); AString s=i.tostring (); -String s2=integer.tostring (5); -         intS3=integer.parseint ("123"); the     } -}

Two: Automatic package unpacking

Automatic package unpacking is a mechanism introduced by JDK5.0.

Packaging: Objects based on the underlying data type

Unpack: Object--The underlying data type.

Automatic package unpacking refers to the automatic package and unpacking operation at the right time.

Commonly used in collection classes.

ImportJava.util.*; Public classTest2 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubList l=NewArrayList (); L.add (1); L.add (2.5); L.add (true); intI= (int) L.get (1); BooleanB= (Boolean) L.get (2); }}

Java basic type wrapper class with automatic package unpacking

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.