共同点:将字符串解析为有符号的十进制整数,如果转换不成功,会抛出NumberFormatException异常。
不同点:
Integer.parseInt(String):方法原型是public static int parseInt(String s) throws NumberFormatException。等效于Integer.valueOf(String).intValue()。
Integer.valueOf(String):方法原型是public static Integer valueOf(String s) throws NumberFormatException。等效于new Integer(Integer.parseInt(s))
,也就是说,前者返回的是int变量,而后者返回的是Integer对象,因此前者也就不具有对象所拥有的方法、属性等用法。