How to convert a Java String to an Int?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Feb-2018 07:31:40
Advertisements