1 String number = "10";
2 int result = Integer.parseInt(number);
3 System.out.println(result);
4Copy
1// You will receive an error if there are non-numeric characters in the String.
2String num = "5";
3int i = Integer.parseInt(num);
1int sample2 = Integer.parseInt("47"); // returns 47
2int sample3 = Integer.parseInt("+4"); // returns 4
1class scalerAcademy {
2 public static void main ( String args [] ) {
3 String str = "789"; // creating a string
4 Integer ans = Integer.valueOf(str); // passing the value to an Integer class
5 Integer ans1 = Integer.valueOf(str,16); // passing radix value as int
6
7 System.out.println(ans); //outputs 789
8 System.out.println(ans1); // outputs 1929
9 }
10}