1int result = Integer.parseInt("500");
2System.out.println(result) // prints 500 as int
1 String number = "10";
2 int result = Integer.parseInt(number);
3 System.out.println(result);
4Copy
1There are two methods available in java to convert string to integer.
2One is
3Integer.parseInt() method and another one is
4Integer.valueOf() method. Both these methods are static methods
5of java.lang.Integer class. Both these methods throw
6NumberFormatException if input string is not a valid integer.