Java Program to convert a String to int

Java 8Object Oriented ProgrammingProgramming

Use the parseInt() method in Java to convert a String to int.

Firstly, include a string.

String str = "999";

Now, let us convert it to int.

int val = Integer.parseInt(str);

Let us see the complete example.

Example

 Live Demo

import java.util.Random;
public class Demo {
   public static void main( String args[] ) {
      String str = "999";
      int val = Integer.parseInt(str);
      System.out.println("Integer = "+val);
   }
}

Output

Integer = 999
raja
Published on 13-Nov-2018 11:40:13
Advertisements