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
1int foo;
2try {
3 foo = Integer.parseInt(myString);
4}
5catch (NumberFormatException e)
6{
7 foo = 0;
8}
9