`
shifulong
  • 浏览: 56502 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java Integer的比较

阅读更多

    /**
     * A constant holding the minimum value an {@code int} can
     * have, -2<sup>31</sup>.
     */
    public static final int   MIN_VALUE = 0x80000000;

    /**
     * A constant holding the maximum value an {@code int} can
     * have, 2<sup>31</sup>-1.
     */
    public static final int   MAX_VALUE = 0x7fffffff;

 

        Long l = 1L;
        int i = 1;
        System.out.println(l == i);
        System.out.println(i == l);
        //true
        //true

        System.out.println(new Integer(1) == new Long(1L));
        // compile error

//equals 先intanceof 在比值
        System.out.println(new Long(1L).equals(1));
        // false 

        System.out.println(new Integer(1) == new Integer(1));
        // false

        System.out.println(new Integer(1) == 1);
        // true

        System.out.println(1 == new Integer(1));
        // true

//缓存 -128--127
        System.out.println(Integer.valueOf(1) == Integer.valueOf(1));
        //true

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics