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);
4
1//parsing string to int
2String numberToParse = "420";
3int number = 0;
4
5try{
6 number = Integer.parseInt(numberToParse);
7}catch(NumberFormatException e){
8 //the string cannot be parsed into a number
9 //ex Integer.parseInt("d15");
10 e.printStackTrace();
11}
12
13System.out.println(number);