Parses the string argument as a signed integer in the radix
specified by the second argument. The characters in the string
must all be digits of the specified radix (as determined by
whether java.lang.Character.digit(char, int)
returns a
nonnegative value), except that the first character may be an
ASCII minus sign '-'
('\u002D'
) to
indicate a negative value or an ASCII plus sign '+'
('\u002B'
) to indicate a positive value. The
resulting integer value is returned.
An exception of type NumberFormatException
is
thrown if any of the following situations occurs:
null
or is a string of
length zero.
java.lang.Character.MIN_RADIX
or
larger than java.lang.Character.MAX_RADIX
.
'-'
('\u002D'
) or plus sign
'+'
('\u002B'
) provided that the
string is longer than length 1.
int
.
Examples:
parseInt("0", 10) returns 0 parseInt("473", 10) returns 473 parseInt("+42", 10) returns 42 parseInt("-0", 10) returns 0 parseInt("-FF", 16) returns -255 parseInt("1100110", 2) returns 102 parseInt("2147483647", 10) returns 2147483647 parseInt("-2147483648", 10) returns -2147483648 parseInt("2147483648", 10) throws a NumberFormatException parseInt("99", 8) throws a NumberFormatException parseInt("Kona", 10) throws a NumberFormatException parseInt("Kona", 27) returns 411787
s | the String containing the integer
representation to be parsed | |
radix | the radix to be used while parsing s . |
NumberFormatException | if the String
does not contain a parsable int . |
Diagram: Number