java tutorial - Java parseInt() method - java programming - learn java - java basics - java for beginners



Java numbers parseint

Learn Java - Java tutorial - Java numbers parseint - Java examples - Java programs

Description

The parseInt () method is used in Java to obtain a primitive data type of a particular string, in other words, it converts a string to a number. The parseXxx () method is a static method and can have one argument or two.

Syntax

The whole variant of the method is given below:

static int parseInt(String s)
static int parseInt(String s, int radix)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • s is a string representation of a decimal value.
  • radix - will be used to convert a string to an integer.

Return value

  • parseInt (String s): returns an integer (only in decimal system).
  • parseInt (int i): returns an integer, given the string representation of decimal, binary, octal and hexadecimal (radix is 10, 2, 8 or 16, respectively) of the numbers as inputs.

Sample Code

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);
   }
}
click below button to copy the code. By - java tutorial - team

Output

9
5.0
1092

Related Searches to Java parseInt() method