Common types in java and common types in java

Source: Internet
Author: User

Common types in java and common types in java

1. Convert the String to an integer (String ---> int)
Method 1:
(1) int I = Integer. parseInt (String s );

Among them, (1) is actually the number we often use to convert s to a 10-digit number. In fact, the default is to call int I = Integer. parseInt ("123", 10 );

(2) I = Integer. parseInt (String s, int radix );

The range of radix is 2 ~ If the value range is greater than 36, an exception is thrown. The length of s cannot exceed 7. Otherwise, an exception is thrown.

Method 2:

Int I = Integer. valueOf (my_str). intValue ();

Note: The methods for converting a string to Double, Float, and Long are similar to those above.

2. How to convert an integer to a String (int ---> String)

(1) String s = String. valueOf (I );
(2) String s = Integer. toString (I );
(3) String s = "" + I;
Note: Convert Double, Float, and Long into stringsSimilar to the above.

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.