How to convert String to Integer in java

realNameHidden - Apr 29 '23 - - Dev Community

for explanation watch the video


import java.util.*;
import java.lang.*;
class Demo{
    public static void main(String[] args){
        String s = "9999";
        int num1 = Integer.parseInt(s);
        System.out.println(num1);
        int num2 = Integer.valueOf(s);
        System.out.println(num2);
    }   
}


Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .