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.pr
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/04 14:33:50
![Integer.parseInt()和这个Integer.valueOf()有什么区别么?public class Shiyan {public static void main(String[] args) {String chuan=](/uploads/image/z/5170348-28-8.jpg?t=Integer.parseInt%28%29%E5%92%8C%E8%BF%99%E4%B8%AAInteger.valueOf%28%29%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB%E4%B9%88%3Fpublic+class+Shiyan+%7Bpublic+static+void+main%28String%5B%5D+args%29+%7BString+chuan%3D%2282%22%3Bint+zhuan%3DInteger.parseInt%28chuan%29%3Bint+zhuanyi%3DInteger.valueOf%28chuan%29%3BSystem.out.println%28zhuan%29%3BSystem.out.pr)
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.pr
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);
}
}
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.pr
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;像是这样表示是没有编译错误的