Java Program to convert a String to int



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
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements