包装类自动装箱问题

package MONA.demo09_包装类;

public class Demo02{
    public static void main(String[] args) {
        Integer i1 = new Integer(1);
        Integer i2 = new Integer(1);

        //fales  判断的是地址的值
        System.out.println(i1 == i2);

        //true  判断的是实际的值
        System.out.println(i1.equals(i2));

        //自动装箱
        //在jdk1.5自动装箱时,如果数值在byte范围之内,不会新创建对象空间而是使用原来已有的空间
        //byte类型的取值范围为-128到127
        Integer i3 = 100;//这行代码等于Integer i3 = new Integar(value:100)
        Integer i4 = 100;//此100会使用i3的空间
        //本应该是false,但是i3和i4使用的是同一个空间,故地址值一样,为true
        System.out.println(i3 == i4);
        //true
        System.out.println(i3.equals(i4));

        Integer i5 = 666;
        Integer i7 = 666;//此555会使用新的空间
        //false
        System.out.println(i5 == i7);
        //true
        System.out.println(i5.equals(i7));
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值