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

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: 2026-03-11T22:50:41+05:30

415 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements