String与Int的转换

来源:互联网 发布:大乐透真假揭秘知乎 编辑:程序博客网 时间:2024/05/17 23:05

例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();
}
原创粉丝点击