valueOf()包含包含3个相互重载的具体方法。
一、valueOf(String s, int radix)
该方法将字符串s中隐含的数字按照radix指定的进制解析为10进制整数,如果字符串s中隐含非数字字符,则抛出 NumberFormatException 异常
例子
Integer.valueOf("1a", 16);
上面例子的结果应该是16+10=27(a表示16进制中的10),valueOf方法将1a解释为10进制数
二、valueOf(String s)
该方法相当于调用 Integer.valueOf(“123”, 10) ,即将默认的参数10省略,返回的是字符串中隐含数字的对应十进制整数。同样也会抛出NumberFormatException 异常
例子
Integer.valueOf("123")
结果为:123
三、valueOf(int i)
该方法将一个int类型的数字封装成Integer的一个对象,是创建Integer对象的常用方法。
例子
Integer integer = Integer.valueOf(6)
integer就是一个Integer类型的对象,该对象只包含一个int类型字段,该字段的值为6。