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