Cannot convert String to Integer in Java
This question already has an answer here:
Here's the way I prefer to do it:
Edit (08/04/2015):
As noted in the comment below, this is actually better done like this:
String numStr = "123";
int num = Integer.parseInt(numStr);
An Integer
can't hold that value. 6042076399 (413424640921 in decimal) is greater than 2147483647, the maximum an integer can hold.
Try using Long.parseLong
.
That's the correct method, but your value is larger than the maximum size of an int
.
The maximum size an int
can hold is 231 - 1, or 2,147,483,647. Your value is 6,042,076,399. You should look at storing it as a long
if you want a primitive type. The maximum value of a long is significantly larger - 263 - 1. Another option might be BigInteger
.
上一篇: Java字符串到整数转换
下一篇: 无法将字符串转换为Java中的整数