The relationship is as follows:
What if they convert each other?
Package the basic variables into the packaging objects by passing in parameters to the corresponding package, and convert the packaging objects into the basic type variables by using the xxxValue () method provided by the packaging class. As follows:
| The code is as follows: |
Copy code |
Public class TestWrapper { Public static void main (String [] args) { Int I = 100; // Convert int type to Integer type Integer iObj = new Integer (I ); // Convert Integer-type objects to int-type objects Int m = iObj. intValue (); } } |
The packaging class can convert between the basic type variables and strings:
All packaging classes except Character provide the parseXXX () method to convert a specific string to a basic type variable;
The String class provides the valueOf () method to convert the basic type ratio to a String.
| The code is as follows: |
Copy code |
Public static void main (String [] args) { String iStr = "123 "; Int I = Integer. parseInt (iStr ); System. out. println (I ); String nStr = String. valueOf (100.234 ); System. out. println (nStr ); } |