How to convert a Java String to an Int?


The parseXxx() method is used to get the primitive data type of a certain String. In this case to convert a String to integer you could use the parseInt() method.

Example

 Live Demo

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

Output

9
5.0
1092

Updated on: 30-Jul-2019

190 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements