Java parseInt() Method
The parseInt() method parses a string argument as a signed decimal integer.
If the method has two parameters, the string argument is parsed as a signed integer in the radix specified by the second parameter.
Syntax
All Number-derived class parseInt methods have a format similar to the following:
static int parseInt(String s) static int parseInt(String s, int radix)
Parameters
s-- a string in decimal representation.
radix-- the specified radix.
Return Value
-
parseInt(String s):Returns the integer value represented by the argument in decimal.
parseInt(int i):The integer represented by the string argument in the specified radix (the radix can be in base 10, 2, 8, or 16, etc.).
Example
public class Test{
public static void main(String args[]){
int x =Integer.parseInt("9");
double c = Double.parseDouble("5");
int b = Integer.parseInt("444",16);
System.out.println(x);
System.out.println(c);
System.out.println(b);
}
}
Compile the above program; the output is:
9 5.0 1092
Other Extensions
Java Number Class