我是靠谱客的博主 内向饼干,这篇文章主要介绍Integer的比较,现在分享给大家,希望可以做个参考。

public class DebugIntegerTests {
    public static void main(String[] args) {
        System.out.println("基于断点方式分析和测试整数池");
        Integer a1=100;
        Integer a2=100;//Integer.valueOf(100)
        Integer a3=200;//Integer.valueOf(200)
        Integer a4=200;
        System.out.println(a1==a2);//true
        System.out.println(a3==a4);//false
		//Integer的范围是“-128~127”,当在这个范围内是从IntegerCache中直接获取
		//当超过这个范围会new一个新的Integer对象出来 
        Integer a5=new Integer(100);
        System.out.println(a1==a5);//false
        int a6=100;
        System.out.println(a5==a6);//true,此时a5会进行拆箱操作a5.intValue()
    }
}

最后

以上就是内向饼干最近收集整理的关于Integer的比较的全部内容,更多相关Integer内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部