Summary of conversions between string,integer,int types

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.