1.先看看该方法的实现
public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
}
2.事实上他可以有两个参数,
public static int parseInt(String s,int radix)
意味着将字符串s按照radix进制转换成整数。太抽象了,看一看例子:
public class Solution {
public static void main(String args[]) {
int x=Integer.parseInt("11");
System.out.println(x);
double y = Double.parseDouble("11");
System.out.println(y);
int z = Integer.parseInt("11",16);
System.out.println(z);
int w = Integer.parseInt("11", 8);
System.out.println(w);
int Q = Integer.parseInt("11", 2);
System.out.println(Q);
}
}
结果:
11
11.0
17
9
3
|