I believe that all of you are very familiar with the basic data types, such as int, float, double, Boolean, Char, and so on. Basic data types do not have the properties of the object, such as the basic type cannot invoke the method, the function is simple ... , Java provides a wrapper class for each base data type, so that we can manipulate the base data type as an operand, in order for the basic data type to have the properties of the object.
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
We will walk through the steps in the following sections, the table anxious Oh ~ ~
Task
We take the Integer wrapper class as an example to see the characteristics of the wrapper class.
How to construct the Integer wrapper class:
As shown in the following code:
Common methods for integer wrapper classes:
The following program lists the conversion between the Integer type and the basic data type, and first recognize it with the results of the operation.
1 Public classHelloWorld {2 Public Static voidMain (string[] args) {3 4 //defines an int type variable with a value of5 intScore1 = 86; 6 7 //Create an Integer wrapper class object that represents the value of the variable score18Integer score2=NewInteger (score1);9 Ten //converting an Integer wrapper class to a double type One Doublescore3=Score2.doublevalue (); A - //converting an Integer wrapper class to a float type - floatscore4=Score2.floatvalue (); the - //converting an Integer wrapper class to an int type - intScore5 =Score2.intvalue (); - +System.out.println ("Integer wrapper class:" +score2); -System.out.println ("Double type:" +score3); +System.out.println ("Float type:" +Score4); ASYSTEM.OUT.PRINTLN ("int type:" +score5); at } -}
Java Basics: Wrapper classes for basic data types in Java (primarily for easier conversion between different data types)