ITeye博客

java Integer的比较

shifulong · 2016-01-18 20:09 · java · Integer · 编程语言 · Markdown


    /**
     * 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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。