Easy Tutorial
❮ Java String Indexof Java Object Equals ❯

Java parseInt() Method

Java Number Class


The parseInt() method is used to parse the string argument as a signed decimal integer.

If the method has two arguments, it parses the string argument as a signed integer using the specified radix.

Syntax

All Number derived classes have a similar format for the parseInt method:

static int parseInt(String s)

static int parseInt(String s, int radix)

Parameters

-

s -- The string representation in decimal.

-

radix -- The specified radix.

Return Value

-

parseInt(String s): Returns the integer value represented by the decimal parameter.

-

parseInt(int i): Returns the integer represented by the string argument using the specified radix (which can be 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);
    }
}

Compiling the above program will output:

9
5.0
1092

Java Number Class

❮ Java String Indexof Java Object Equals ❯