Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java List Interface

Java Queue Interface

Java Map Interface

Java Set Interface

Java Data Structures

Java Collections Algorithms

Java Miscellaneous

Advanced Java

Java APIs & Frameworks

Java Useful Resources

Java - parseInt() Method



Description

This method is used to get the primitive data type of a certain String. parseXxx() is a static method and can have one argument or two.

Syntax

Following are all the variants of this method −

static int parseInt(String s)
static int parseInt(String s, int radix)

Parameters

Here is the detail of parameters −

  • s − This is a string representation of decimal.

  • radix − This would be used to convert String s into integer.

Return Value

  • parseInt(String s) − This returns an integer (decimal only).

  • parseInt(int i) − This returns an integer, given a string representation of decimal, binary, octal, or hexadecimal (radix equals 10, 2, 8, or 16 respectively) numbers as input.

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);
   }
}

This will produce the following result −

Output

9
5.0
1092
java_numbers.htm
Advertisements