How to convert a String into int in Java?



The Integer wrapper class of the java.lang package provides a method named parseInt() using this method you can convert a String variable to an integer variable.

Example

Live Demo

public class Test {
   public static void main(String args[]) {
      String data = "123";
      int num = Integer.parseInt(data);
      System.out.println(data);
   }
}

Output

123

Advertisements