记录每天的学习情况。加油。

 /**
* 测试包装类
* @author 小白
*
*/
public class TestWrappedClass {
public static void main(String[] args) { //基本数据类型转成包装类对象
Integer a = new Integer(3);
Integer b = Integer.valueOf(30); //把包装类对象转成基本数据类型
int c = b.intValue();
double d = b.doubleValue(); //把字符串转成包装类对象
Integer e = new Integer("99999");
Integer f = Integer.parseInt("999888"); //把包装类对象转换成字符串
String str = f.toString(); //常见的常量
System.out.println("int类型最大的整数:"+Integer.MAX_VALUE);
}
}
 /**
* 测试自动拆箱,自动装箱
* @author 小白
*
*/
public class TestAutoBox {
public static void main(String[] args) {
Integer a = 234; //自动装箱,相当于Integer a = Integer.valueOf(234);
int b = a; //自动拆箱 ,编译器会修改成:int b = a.intValue(); Integer c = null;
if(c!=null){
int d = c; //自动拆箱:调用了:c.intValue();
} //缓存[-128,127]之间的数字.实际就是系统初始的时候,创建了[-128,127]之间的一个缓存数组
//当我们调用valueOf()的时候,首先检查是否在[-128,127]之间,如果在这个范围则直接从缓存数组中拿出已经建好的对象
//如果不在这个范围,则创建新的Integer对象。
Integer in1 = -128;
Integer in2 = -128;
System.out.println(in1==in2); //true因为-128在缓存范围内
System.out.println(in1.equals(in2));//true
System.out.println("#########");
Integer in3 = 1234;
Integer in4 = 1234;
System.out.println(in3==in4);//false因为1234不在缓存范围内
System.out.println(in3.equals(in4));//true
} }
05-11 14:49