Conversion of string and int in Java

Source: Internet
Author: User

converting string strings to integer int
A. There are 2 methods:
1). int i = Integer.parseint ([String]); or i = Integer.parseint ([string],[int Radix]);
2). int i = integer.valueof (my_str). Intvalue ();
PS:
the string turns into Double, Float, and Long in a similar way.
The first method: I=integer.parseint ([String]),//using static methods directly, does not produce extra objects, but throws an exception.
The second method: I=integer.valueof (MY_STR). Intvalue ();//integer.valueof (my_str) equals the new Integer (Integer.parseint (MY_STR) ), an exception will also be thrown.

Second, convert integer int to string string
A. There are 3 ways:
1.) String s = string.valueof (i);
2.) String s = integer.tostring (i);
3.) String s = "" + I;
PS:
Double, Float, and Long turn into strings in a similar way.
1th Method: S=string.valueof (i);//Use the static method of the String class directly, producing only one object.
The 3rd method: s= "" + i; A two string object is generated.

Conversion of string and int in Java

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.