How to convert a String into int in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Jan-2018 08:33:11
Advertisements