Convert String to Java int



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
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements