在 Java 中要將 String 類型轉(zhuǎn)化為 int 類型時(shí),需要使用 Integer 類中的 parseInt() 方法或者 valueOf() 方法進(jìn)行轉(zhuǎn)換.
方法 1
String str = "123";
try {
int a = Integer.parseInt(str);
} catch (NumberFormatException e) {
e.printStackTrace();
}
方法 2
String str = "123";
try {
int b = Integer.valueOf(str).intValue()
} catch (NumberFormatException e) {
e.printStackTrace();
}
作者:a772304419
來源:CSDN
原文:https://blog.csdn.net/a772304419/article/details/79723249
版權(quán)聲明:本文為博主原創(chuàng)文章絮爷,轉(zhuǎn)載請(qǐng)附上博文鏈接廷蓉!