Basic types of Java and their wrapper classes

Source: Internet
Author: User

Java provides a total of eight basic data types, namely: Byte,short,int,long,float,double,boolean,char. Their corresponding packaging classes are in the Java.lang package, respectively, corresponding to: Byte,short

Integer,long,float,double,boolean,character.

When you have to use objects or reference data types in some places (collection classes), the basic data types cannot be used because their storage principles and reference data types are completely different. It is simple to convert a variable of the basic data type to a wrapper type, create or invoke a static method of the wrapper class with the new statement valueof (), and pass in the basic type variable as a parameter.

    int 9;   // Defining Variables    Integer it = integer.valueof (i);  // Use the valueof () method to turn I into an integer variable    New Integer (i);    // Construction Method Creation         =    New ArrayList ();    // Create a collection variable    of list type List.add (it);        // put the package type of it into the list

The wrapper class is converted to the base data type, calling the wrapper class object's Intvalue (), Shortvalue (): Method

    Integer it = integer.valueof (i);    It.intvalue ();

Basic types of Java and their wrapper classes

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.