Integer.parseInt(string s) method
Use the parseInt() method of the java Integer class to convert. Since non-numbers may appear in the string to be converted, the exception of NumberFormatException needs to be caught.
Example:
public class test1 {
public static void main(String[] args) {
String test_str = "123";
try {
int test_int = Integer.parseInt(test_str);
System.out.println(test_int);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}