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之间的数据,做了一个数据缓冲池
//如果数据时该范围内的,每次并不创建新的空间
}
}
Java关于Integer面试题
最新推荐文章于 2024-08-08 16:17:24 发布