Java关于Integer面试题

package day13_Integer;
/*
 * JDK5的新特性:
 * 	自动装箱:把基本类型转为包装类类型
 * 	自动拆箱:把包装类类型转为基本类型
 * 
 * Integer面试题?
 * 		看程序写结果。
 * 	注意:Integer的数据直接赋值,如果在-128到127之间,会直接从缓冲池里获取数据。
 * */
public class IntegerDemo4 {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//定义一个int类型的包装类类型变量
		//Integer i = new Integer(100);
		Integer i=100;
		i+=200;//可以的
		System.out.println("i:"+i);
		System.out.println("------------");
		
		//面试题
		Integer in= new Integer(127);
		Integer in2 = new Integer(127);
		System.out.println(in==in2);//false
		System.out.println(in.equals(in2));//true
		System.out.println("------------");
		
		Integer in3= new Integer(128);
		Integer in4 = new Integer(128);
		System.out.println(in3==in4);//false
		System.out.println(in3.equals(in4));//true
		System.out.println("------------");
		
		Integer in5= 128;
		Integer in6 = 128;
		System.out.println(in5==in6);//false
		System.out.println(in5.equals(in6));//true
		System.out.println("------------");
		
		Integer in7= 127;
		Integer in8 = 127;
		System.out.println(in7==in8);//true
		System.out.println(in7.equals(in8));//true
		System.out.println("------------");
		
		//通过查看源码,我们就知道了,针对-128到127之间的数据,做了一个数据缓冲池
		//如果数据时该范围内的,每次并不创建新的空间
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值