一、包装类(针对八种基本数据类型相应的引用类型–包装类.

1)包装类和基本数据类型的相互转换

装箱:基本类型->包装类型

拆箱:包装类型->基本类型

//以下是int类型和char类型演示。public class temp1 {public static void main(String[] args) {//intInteger的装箱(基本类型->包装类型)和拆箱(包装类型->基本类型)//1,手动装箱:int n=10;Integer integer =new Integer(n);//或Integer integer1=Integer.valueOf(n)//2.手动拆箱int i=integer.intValue();//jdk5后,就可以自动装箱和自动拆箱int a=20;char ch='g';//1.自动装箱Integer integer2=a;//底层使用的依然是Integer.valueOf(a)Character character=ch;//2.自动拆箱int b=integer2;char ch1=character;}}

插入知识点:三元运算符

public class temp1 {public static void main(String[] args) {Object obj1=true?new Integer(1):new Double(2.0);System.out.println(obj1);//实际输出为1.0//因为三元运算符是一个整体,自动类型转换}}