//装箱:将基本数据类型变为包装类的过程。
public class WrapperDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 30;
Integer i = new Integer(x); //装箱操作
System.out.println("装箱前:"+i);
int temp = i.intValue(); //拆箱操作:将包装类变为基本数据类型
System.out.println("拆箱后:"+temp);
float y = 39.8f;
Float a = new Float(y); //装箱
System.out.println("装箱前:"+a);
float b = a.floatValue(); //拆箱
System.out.println("拆箱后:"+b);
}
}
/*
运行结果:
装箱前:30
拆箱后:30
装箱前:39.8
拆箱后:39.8
*/
public class WrapperDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 30;
Integer i = new Integer(x); //装箱操作
System.out.println("装箱前:"+i);
int temp = i.intValue(); //拆箱操作:将包装类变为基本数据类型
System.out.println("拆箱后:"+temp);
float y = 39.8f;
Float a = new Float(y); //装箱
System.out.println("装箱前:"+a);
float b = a.floatValue(); //拆箱
System.out.println("拆箱后:"+b);
}
}
/*
运行结果:
装箱前:30
拆箱后:30
装箱前:39.8
拆箱后:39.8
*/