Java provides a total of eight basic data types, namely: Byte,short,int,long,float,double,boolean,char. Their corresponding packaging classes are in the Java.lang package, respectively, corresponding to: Byte,short
Integer,long,float,double,boolean,character.
When you have to use objects or reference data types in some places (collection classes), the basic data types cannot be used because their storage principles and reference data types are completely different. It is simple to convert a variable of the basic data type to a wrapper type, create or invoke a static method of the wrapper class with the new statement valueof (), and pass in the basic type variable as a parameter.
int 9; // Defining Variables Integer it = integer.valueof (i); // Use the valueof () method to turn I into an integer variable New Integer (i); // Construction Method Creation = New ArrayList (); // Create a collection variable of list type List.add (it); // put the package type of it into the list
The wrapper class is converted to the base data type, calling the wrapper class object's Intvalue (), Shortvalue (): Method
Integer it = integer.valueof (i); It.intvalue ();
Basic types of Java and their wrapper classes