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: 2019-07-30T22:30:21+05:30

359 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements