网上查询parseint方法参数的字符串是可以有非数字的
但我自己尝试这个方法的时候就报错
你可以点进去看一下parseInt的具体实现,
//...
char firstChar = s.charAt(0);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (firstChar != '+') {
throw NumberFormatException.forInputString(s);
}
if (len == 1) { // Cannot have lone "+" or "-"
throw NumberFormatException.forInputString(s);
}
i++;
}
//...
中间有这么一段代码,被解析的字符串是允许第一位的正负号的(不能只有正负号)