How to convert string and INT in Java

Source: Internet
Author: User

 1. Convert string to int

There are two methods:

1). Int I = integer. parseint ([String]); or I = integer. parseint ([String], [int Radix]);

Here I = integer. parseint ([String], [int Radix])

For example:

String STR = "123 ",
Int I = integer. parseint (STR, 8 ),
The following parameter indicates the value obtained by. I when STR is regarded as the number of hexadecimal notation (I is a 10 hexadecimal notation)
For example, I = integer. parseint (STR, 5). I = 38. Indicates 1*5*5 + 2*5 + 3.

2). Int I = integer. valueof (my_str). intvalue ();
 

2. Convert int to string

There are three methods:

1.) string S = string. valueof (I );

2.) string S = integer. tostring (I );

3.) string S = "" + I;

 

From: http://www.webkaka.com/blog/archives/the-conversion-of-String-and-Int-in-Java.html

Related Article

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.