Parse a string as a signed integer.
The Integer.parseInt() method parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be a minus sign '-' or plus sign '+'.
An optional second argument specifies the radix (base) for parsing, supporting bases from 2 to 36. This is useful for parsing binary, octal, and hexadecimal strings. NumberFormatException is thrown if the string cannot be parsed as an integer.
This method is one of the most commonly used parsing methods in Java. It is used for processing command-line arguments, reading configuration values, parsing user input, and converting string representations of numbers from various sources.
| Name | Description | Optional |
|---|---|---|
s |
The String to be parsed. | No |
radix |
The radix to use when parsing the string. | Yes |
Integer.parseInt("42"); // 42
Integer.parseInt("-7"); // -7
Integer.parseInt("FF", 16); // 255
Integer.parseInt("1010", 2); // 10