String转int

来源:互联网 发布:windows查看显存 编辑:程序博客网 时间:2024/06/15 14:40

String转int

String str = “123”;

方法1:

int a = Integer.parseInt(str);

方法2:

int b = Integer.valueOf(str);

可能报错 : NumberFormatException
错误:
int a = Integer.getInteger(str) 方法不行.

public static int parseInt(String s) throws NumberFormatException {
throw new RuntimeException(“Stub!”);
}
public static Integer valueOf(String s) throws NumberFormatException {
throw new RuntimeException(“Stub!”);
}
//可能是跟拆装箱有关的方法吧
public static Integer getInteger(String nm) {
throw new RuntimeException(“Stub!”);
}