我是靠谱客的博主 鲤鱼冷风,这篇文章主要介绍Integer包装类的判断问题,现在分享给大家,希望可以做个参考。

public class IntegerNote {
    public static void main(String[] args) {
        Integer i = new Integer(1);
        Integer j = new Integer(1);
        System.out.println(i == j);//False,==比较对象地址
        Integer m = 1;//底层Integer.value0f(1); ->阅读源码
        Integer n = 1;//底层Intege.valueOf(1);
        System.out.println(m == n);//True
//所以,这里主要是看范围 -128 ~ 127就是直接返回static final Integer cache[]里对应的值,否则,就重新new Integer(xx);
        Integer h = 128; //底层Integer.valueOf();
        Integer y = 128;
        System.out.println(h == y);//False
        Integer i1=127;
        Integer i2=new Integer(127);
        System.out.println(i1==i2);//False
        int n1=127;
        Integer n2=127;
        System.out.println(n1==n2);//True只要有基本数据类型==就是判断值是否相等
        int j1=128;
        Integer j2=128;
        System.out.println(j1==j2);//True
    }
}

韩顺平老师的讲解笔记

最后

以上就是鲤鱼冷风最近收集整理的关于Integer包装类的判断问题的全部内容,更多相关Integer包装类内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部