Convert String to Java int

Java 8Object Oriented ProgrammingProgramming

Use the Integer.parseInt() method to convert string to int.

Here is our string −

String myStr = new String("999");

Converting the string into integer.

int intVal = Integer.parseInt(myStr);

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String myStr = new String("89");
      // converting string to int
      int intVal = Integer.parseInt(myStr);
      System.out.println(intVal);
   }
}

Output

89
raja
Published on 13-Dec-2018 13:52:07
Advertisements