one, the conversion between the basic data type and its corresponding encapsulation class
basic data types are converted to encapsulated classes
1 • Direct Assignment (automatic packaging)
Integer i=3;
2 • Using the enclosing parameter constructor of the encapsulated class (instantiated)
Integer i=new integer (3);
3 • Use the valueof () method provided by the encapsulation class (static method)
Integer i=integer.valueof (3);
encapsulate class to basic data type
1. Direct assignment (Automatic unpack)
Integer i=new integer (2);
int j=i;
2 • Use the value () method provided by the encapsulation class
Integer i=new integer (3);
int J=i.intvalue ();
float F=i.floatvalue ();
ii. conversion between basic data types and strings Convert base data type to String
1 • Using the valueof () method of the String class (static method)
String s=string.valueof (123);
2 • Use the ToString () method of the encapsulated class (static method)
String s=integer.tostring (3);
3 • Use string connector "+"
String s= "" +123;
string conversion to basic data type
1. Use the static method of the encapsulation class
int I=integer.parseint ("12");
third, the encapsulation class and the string between the conversion string conversion to encapsulated class
1 • Using the enclosing parameter constructor of the encapsulated class (instantiated)
Integer i=new integer ("123");
2 • Using the valueof () method of the Encapsulation class
Integer i=integer.valueof ("123");
encapsulate class to String
1 • Use string connector "+"
Integer i=new integer (123);
String s= "" +i;
2 • Using the ToString () method of the encapsulated class
Integer i=new integer (123);
String s=i.tostring ();