Java wrapper class

Source: Internet
Author: User
Tags class definition

I. Packing CLASS definition

Java is not a purely object-oriented language. The Java language is an object-oriented language, but Java's basic data types are not object-oriented. But we are actually making

It is often necessary to convert basic data into objects for ease of operation. For example: In the operation of a collection, this is where we need to convert the basic type data into objects.

Packaging classes are located in the Java.lang package, you do not need to import, the system automatically imported. The 8 wrapper classes in Java are: Byte, short, Integer, Long, Float, Double,

Character, Boolean, they are all used the same way, enabling bidirectional conversion of native data types to wrapper types

Object relationships for wrapper classes and base data types:

Second, the application of packaging class

 PackageCom.yyx.pratice; Public classJavapratice { Public Static voidMain (string[] args) {intAge1 = 22; //Manual BoxingInteger AgeInteger1 =NewInteger (AGE1); //Manual Unpacking        intAgeOther1 =Ageinteger1.intvalue (); System.out.println (AgeInteger1+" "+ageOther1); //Automatic BoxingInteger AgeInteger2 =Age1; //Automatic Unpacking        intAgeOther2 =AgeInteger2; System.out.println (ageinteger2.tostring ()+" "+ageOther2); String Str= "25"; intAge2=integer.parseint (str);                System.out.println (Age2); //converts a string to int by decimal        intAge3=integer.parseint (str, 10); //converts a string to int by 16 binary        intAge4=integer.parseint (str, 16); System.out.println (Age3+" "+age4); }}

Java wrapper class

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.