当前位置: > Integer.parseInt()和这个Integer.valueOf()有什么区别么?...
题目
Integer.parseInt()和这个Integer.valueOf()有什么区别么?
public class Shiyan {
public static void main(String[] args) {
String chuan="82";
int zhuan=Integer.parseInt(chuan);
int zhuanyi=Integer.valueOf(chuan);
System.out.println(zhuan);
System.out.println(zhuanyi);
}
}

提问时间:2021-01-05

答案
static int parseInt(String s)
将字符串参数作为有符号的十进制整数进行分析.
static Integer valueOf(int i)
返回一个表示指定的 int 值的 Integer 实例.
static Integer valueOf(String s)
返回保持指定的 String 的值的 Integer 对象.
从返回值可以看出他们的区别 parseInt()返回的是基本类型int
而valueOf()返回的是包装类Integer Integer是可以使用对象方法的 而int类型就不能和Object类型进行互相转换
int zhuan=Integer.parseInt(chuan);
int zhuanyi=Integer.valueOf(chuan); 为什么你的程序返回值都可以用int来接收呢?因为Integer和int可以自动转换
Integer i = 5; int k = i;像是这样表示是没有编译错误的
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.