Java parseInt() Method
The parseInt() method parses a string argument as a signed decimal integer.
If the method has two arguments, the string argument is parsed as a signed integer using the radix specified by the second argument.
Syntax
The parseInt method format for all Number-derived classes is 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 decimal argument.
-
parseInt(int i): The integer represented by the string argument in the specified radix (the radix can be 10, 2, 8, 16 and so on).
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
The Java Number class