第1个回答 2008-10-10
大家都说了是返回的类型不同.
但不赞同闫国上的的"较高的版本中:integer.valueof()也可以返回整形数值。 " 实际上integer.valueof()并不能返回int型.
在JDK1.5之后,也称JDK5.0之后,基本数据类型和其相应的封装类在运算与赋值时可以自动转换,但是在做为参数时不是会自动转换的.
你的代码中:
Integer.parseInt(chuan)返回值是int型的.
Integer.valueOf(chuan)返回值是Integer型的.把Integer赋值给int型的话,JRE会自己完成这些工作.
区别还是有的.如果你写一个方法的形参是int型的,比如:
void test(int a){
//todo:
};
当你调用这个方法的时候test(Integer.parseInt(chuan))会翻译通过,但test(Integer.valueOf(chuan))会翻译错误.
第2个回答 2008-10-09
在比较低的版本中:
integer.valueof()返回得是对象;
integer.parseint()返回的是一个整形数值。
在较高的版本中:
integer.valueof()也可以返回整形数值。
第3个回答 2008-10-09
Integer.valueof()返回的是Integer的对象。
Integer.parseInt() 返回的是一个int的值。
第4个回答 2008-10-10
Integer java.lang.Integer.valueOf(String s)
Returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string.
In other words, this method returns an Integer object equal to the value of:
new Integer(Integer.parseInt(s))
Parameters:
s the string to be parsed.
Returns:
an Integer object holding the value represented by the string argument.
Throws:
NumberFormatException if the string cannot be parsed as an integer.
=-================================
int java.lang.Integer.parseInt(String s)
Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.
Parameters:
s a String containing the int representation to be parsed
Returns:
the integer value represented by the argument in decimal.
Throws:
NumberFormatException if the string does not contain a parsable integer.