First, Packaging class
Wrapper class Definition: Object type, which encapsulates the data type with an object-oriented approach. Each wrapper class corresponds to a basic data type, such as Boolean, Char, Byte, short, integer, etc. that correspond to Boolean, char, Byte, short, and int, and have corresponding properties and methods.
Function: ① is very convenient for data type conversion, such as the character type of the number "243", if you want to convert to integer type packaging class is very convenient.
② the wrapper class is also used when the data type that needs to be worn in some cases is an object type.
public class Test {
public static void Main (string[] args) {
Integer i = new integer (1);
Int J = I.intvalue () + 1;
System.out.println (i);
System.out.println (j);
}
}
Second, automatic unpacking and packing
Automatic unpacking and boxing greatly facilitates the operation between the basic data type and the wrapper type. The auto-boxing feature can package the base data type as the appropriate wrapper type, while the auto-unpacking feature can unpack the wrapper type to the appropriate base data type.
public class Test {
public static void Main (string[] args) throws exception{
Integer i = 1;
Int J = i + 1;
System.out.println (i);
System.out.println (j);
}
}
Packing class and automatic unboxing