Today, learning the concept of packaging knowledge, about automatic boxing and unpacking and other means to change the data type is very interesting, while the mutual conversion is also worth remembering, of course, in the work practice makes perfect, just to comb the knowledge point, for everyone's reference:
Auto-boxing and auto-unpacking have been implemented since JAVA7, and conversion between int and integer has been realized automatically
Here is the actual operation code
1 Public classinteger04{2 Public Static voidMain (string[] args) {3 //int--->integer4Integer i1=integer.valueof (10);//Returns an integer instance representing the specified int value5 //Create an integer instance by constructing the method6Integer m1=NewInteger (10);//Fundamentals of Encapsulation7 8 //Integer-->int9 intI2=i1.intvalue ();//UnpackingTen One //String-->integer AInteger i3=integer.valueof ("10");//Returns an integer instance that represents the specified string value - - //integer-->string theString s1=i3.tostring ();//returns a specified string - - //String-->int - intI4=integer.parseint ("123");//Note that it must be a pure number . + - //int-->string +String s2=10+ ""; A } at}
where int boxing can be achieved by integer i=new integer (10), or directly call Integer.valueof () method implementation, the same sring converted to an integer can also be implemented according to this method, Unpacking is called the method of Intvalue (), and the integer to string is the method of calling ToString, and string to int requires the parse () method of Integer. However, it is important to note that the string must be a pure number to convert between them, and an int to a string is quite simple: the int+ string is the string, which is the basis for easy forgetting.
In this respect, we feel that it is helpful to remember and understand, and support!
Summary of conversions between string,integer,int types