Java.lang Package Classes

Java Integer - parseUnsignedInt() Method



The java.lang.Integer.parseUnsignedInt() method is used to parse the string argument as an unsigned decimal integer. The characters in the string must all be decimal digits, except that the first character may be an an ASCII plus sign '+' ('\u002B'). The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseUnsignedInt(java.lang.String, int) method.

Syntax

public static int parseUnsignedInt(String s)
                            throws NumberFormatException

Parameters

s Specify a String containing the unsigned int representation to be parsed.

Return Value

Returns the unsigned integer value represented by the argument in decimal.

Exception

Throws NumberFormatException, if the string does not contain a parsable unsigned integer.

Example:

In the example below, the java.lang.Integer.parseUnsignedInt() method is used to parse the string argument as an unsigned decimal integer.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a string holding unsigned int value
    String x = "25";

    //creating unsigned int value
    int y = Integer.parseUnsignedInt(x);

    //printing the string
    System.out.println("The string is: " + x); 

    //printing the unsigned int value
    System.out.println("The int value is: " + y);   
  }
}

The output of the above code will be:

The string is: 25
The int value is: 25

❮ Java.lang - Integer