`
cxjaccp
  • 浏览: 740 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

java,Integer,比较

阅读更多
Integer比较



    public static void main(String[] args) {


        Integer a = 100;
        Integer b =100;
        if (a >= b && a <= b && a != b) {
            System.out.println("哈哈哈");
        }else{
            System.out.println("呵呵呵");
        }
        Integer c = 200;
        Integer d =200;
        if (c >= d && c <= d && c != d) {
            System.out.println("哈哈哈");
        }else{
            System.out.println("呵呵呵");
        }

    }


输出如下

  • 呵呵呵
  • 哈哈哈



原因
Integer在-128到127的值之间使用的是缓存,所以为同一个对象。

我们可以看看源码





分享到:
评论
1 楼 撑起一片天 2016-09-01  
hehehe

相关推荐

Global site tag (gtag.js) - Google Analytics