Example 1:
string str = " 123 ";
Try {
int a = integer . parse int(str);
} catch(NumberFormatException e){
e . printstacktrace();
}
Example 2:
string str = " 123 ";
Try {
int b = Integer.valueOf(str)。 intValue()
} catch(NumberFormatException e){
e . printstacktrace();
}
In the process of conversion, we need to pay attention to the fact that there may be non-numeric cases in the string, so we need to catch and handle exceptions during conversion.