Integer.parseInt will throw an exception when what it's parsing can't be represented as an int
. The first example is almost 10 billion, which is larger than the largest possible int
, which is a little over 2 billion.
Integer.parseInt(String)
delegates to Integer.parseInt(String, 10), the version that takes a radix, and those Javadocs state:
An exception of type NumberFormatException is thrown if any of the following situations occurs:
- The first argument is null or is a string of length zero.
- The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
- Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') or plus sign '+' ('\u002B') provided that the string is longer than length 1.
- The value represented by the string is not a value of type int.
(emphasis mine)
If you need it parsed, you can use Long.parseLong, which will handle larger numbers.