In order for the basic data type to have the properties of the object, Java provides a wrapper class for each of the basic data types, so that we can manipulate the basic data type like an object, and the wrapper class is in the Java.lang package.
Correspondence between the base type and the wrapper class:
The wrapper class provides two main types of methods:
1. Ways to convert this type and other basic types
2. Ways to convert strings and this type and wrapper class to each other
such as: The General method of the integer wrapper class
It is often necessary to convert between the basic type and the wrapper class, and the conversion between the wrapper class and the base type is much easier after JDK1.5 introduces the mechanism of automatic boxing and unpacking.
Boxing: convert the basic type of the corresponding packaging class, so that it has the nature of the object, but also can be divided into manual boxing and automatic packing
unpacking: In contrast to boxing, the wrapper class object is converted to the corresponding basic type value, and can be divided into manual unpacking and automatic unpacking
Conversions between basic types and strings
There are three ways to convert a base type to a string:
1. Use the ToString () method of the wrapper class
2. Using the ValueOf () method of the String class
3. Using an empty string with the base type, you get the string that corresponds to the base type data
Again, there are two ways to convert a string to a basic type:
1. Call the Parsexxx static method of the wrapper class
2. The ValueOf () method that calls the wrapper class is converted to the basic type of wrapper class, and the box is automatically disassembled
Java wrapper class