Exception java. lang. NumberFormatException: For input string:, exception forinputstring

Source: Internet
Author: User

Exception java. lang. NumberFormatException: For input string:, exception forinputstring
When writing a project today, this exception occurs when converting the String type to the Integer type. The record is as follows:

The Code is as follows:

1 String a = "2222222222"; // 10 22 Integer B = Integer. valueOf (a); // converts String type to Integer type

The exception is as follows:

 

Cause & Solution: Integer in a 32-bit compiling environment, the storage length is 32 bits. -2 ^ 31 ~ 2 ^ 31-1;-2,147,483,648 ~ 2,147,483,647. Replace Integer with BigInteger to solve the problem.

The Code is as follows:

String a = "2222222222"; // It is also 10 2 BigInteger B = new BigInteger (a); // String to BigInteger

The important thing is said three times:

You are welcome to point out errors and errors, and make suggestions. I will update them in my blog in time!

You are welcome to point out errors and errors, and make suggestions. I will update them in my blog in time!

You are welcome to point out errors and errors, and make suggestions. I will update them in my blog in time!

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.