JAVA基础(三)·自动装箱和拆箱

public class TestAutoBoxing{
    
    public static void main(String[] args)
    
    	 Integer t1 = new Integer(127);
		    Integer t2 = new Integer(127);
		    System.out.println("t1==t2:"+(t1==t2));
		    Integer t3 = 127;
		    Integer  t4 = 127;
		    System.out.println("t3==t4:"+(t3==t4));
		    System.out.println("t1==t4:"+(t1==t4));
		    Integer t5 = 128;
		    Integer t6 = 128;
		    System.out.println("t5==t6:"+(t5==t6));
		    
		    //运行结果
		    //false,true,false,false
		   /* 适用范围:
		        boolean类型的值
	            所有byte类型的值
	            在-128~127之间的short类型的值
	            在 -128~127之间的int类型的值
	            所有所有在\u00000~\u007F之间的char类型的值       
	    注:当int类型的数据在-128~127的时候,通过自动装箱产生的Integer对象会缓存在内存中的,而试图通过
  自动装箱的方式产生另一个相等值得Integer对象的时候,系统将不会重新生成新的对象而是直接使用
	 内存中已经存在的Integer对象
		   
		   */
		    
		    
		    
		    
		    
		    
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值