Common type conversions in Java

Source: Internet
Author: User

1. Converting a string to an integer (String--->int)
Method One:
(1) int i = Integer.parseint (String s);

which (1) is actually what we often use to convert s to 10, in fact, the default is to call the int i =integer.parseint ("123",ten);  

(2) i = Integer.parseint (String s,int radix);

The range of radix is between 2~ 36 and out of range throws an exception. The length of s can not exceed 7, otherwise it will throw an exception.

Method Two:

  int i = integer.valueof (my_str). Intvalue ();

Note: The string is converted to Double, Float, and Long in the same way as above.

2. How to convert integers to strings (int--->string)

(1) String s = string.valueof (i);
(2) String s = integer.tostring (i);
(3) String s = "" + I;
Note: Double, Float, and Long turn into a string similar to the previous method.

Common type conversions in Java

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.