Integer的自动装箱与拆箱
2016-07-20 10:03
295 查看
Integer的自动装箱与拆箱
//Integer的自动装箱与拆箱
//JVM会自动缓存-128~127范围内的值
public class IntegerDemo {
public static void main(String[] args) {
int a1=10;
Integer a2=10;
Integer a3=10;
Integer a4=new Integer(10);
int b1=1000;
Integer b2=1000;
Integer b3=1000;
Integer b4=new Integer(1000);
System.out.println(a1==a2);//true
System.out.println(a1==a4);//true
System.out.println(a2==a3);//true
System.out.println(a2==a4);//false
System.out.println("1--------");
System.out.println(b1==b2);//true
System.out.println(b1==b4);//true
System.out.println(b2==b3); //false
System.out.println(b2==b4);//false
System.out.println("2--------");
Integer c1=127,c2=128;
int c3=128;
c1=c3;//装箱
System.out.println(c1==c2);//false
System.out.println(c1==c3);//true
System.out.println(c2==c3);//true
System.out.println("3-----------");
Integer d1=127;
Integer d2=127;
System.out.println(d1==d2);//true
d1=128;
d2=128;
System.out.println(d1==d2);//false
}
}
//Integer的自动装箱与拆箱
//JVM会自动缓存-128~127范围内的值
public class IntegerDemo {
public static void main(String[] args) {
int a1=10;
Integer a2=10;
Integer a3=10;
Integer a4=new Integer(10);
int b1=1000;
Integer b2=1000;
Integer b3=1000;
Integer b4=new Integer(1000);
System.out.println(a1==a2);//true
System.out.println(a1==a4);//true
System.out.println(a2==a3);//true
System.out.println(a2==a4);//false
System.out.println("1--------");
System.out.println(b1==b2);//true
System.out.println(b1==b4);//true
System.out.println(b2==b3); //false
System.out.println(b2==b4);//false
System.out.println("2--------");
Integer c1=127,c2=128;
int c3=128;
c1=c3;//装箱
System.out.println(c1==c2);//false
System.out.println(c1==c3);//true
System.out.println(c2==c3);//true
System.out.println("3-----------");
Integer d1=127;
Integer d2=127;
System.out.println(d1==d2);//true
d1=128;
d2=128;
System.out.println(d1==d2);//false
}
}
相关文章推荐
- 只有程序员看的懂的面试圣经|如何拿下编程面试
- 下一次技术面试时要问的 3 个重要问题
- PHP程序员面试 切忌急功近利(更需要注重以后的发展)
- C#常见算法面试题小结
- php 面试碰到过的问题 在此做下记录
- asp.net 面试+笔试题目第1/2页
- asp.net 面试 笔试题目[附答案]第1/3页
- Python爬虫工程师面试问题总结
- 面试心得
- 谈谈最近深圳找工作经历
- 面试相关知识收集
- 面试:(设计,架构)
- 面试总结(php)
- PHP中级面试经历
- 戴维营教育2015年iOS暑期班笔试面试基础考核题
- 一次有意思的面试
- 程序员编程面试取胜的8个技巧
- PHP相关面试中最经常涉及的12个问题
- 面试产品经理必胜8招,就要如此不同凡响
- 产品经理到底该如何自我介绍?