java把字符串“1”转为数字?

怎么把字符串“1”转换成int型的数字1?
怎么把字符串“1”转换成int型的数字1?
怎么把字符串“1”转换成int型的数字1?
怎么把字符串“1”转换成int型的数字1?

img


String str = "123";

try {

    int b = Integer.valueOf(str).intValue()

} catch (NumberFormatException e) {

    e.printStackTrace();

}

Integer.parseInt("1")


Integer.parseInt("1")

Integer对象的静态方法:
Integer.parseInt("1")