8种基本数据类型不是对象,因此JAVA提供了8个对应的包装类
Byte Short Integer Long Character Float Double Boolean
自动装箱:把基本类型用对应的包装类包装起来,使其具有对象的特质,可以调用toString(),equals()等方法
自动拆箱:将Integer,Double等这样引用类型的对象简化为基本类型的数据
以Integer举例:
package Experience;
public class ArrayDemo1 {
public static void main(String[] args){
int a=1;
int b=100;
String he="123";
//基本类型->封装类型
//自动装箱(不调用构造方法,用=自动转换)
Integer i2=b;
//自动拆箱 封装类型----(自动转换)--->基本类型
int c=i2;
System.out.println(Integer.max(a,b));
System.out.println("int的最大值:"+Integer.MAX_VALUE);
System.out.println("int的最小值:"+Integer.MIN_VALUE);
System.out.println("byte的最大值:"+Byte.MAX_VALUE);
System.out.println("byte的最小值:"+Byte.MIN_VALUE);
System.out.println(Math.abs(i2));
//praseInt 是将String类型转化为int类型
System.out.println(Integer.parseInt(he));
//valueof 是将String类型转化为Integer类型
System.out.println(Integer.valueOf(he));
//toString 返回的是字符串类型的 String b=a.toString();
}
}