包装类的优势
1.提供了一系列针对该类型的方法
2.包装类型的默认值都为null
3.自动装拆箱
4.集合中不允许存放基本数据类型
包装类和基本类的对应关系
基本类型 包装类型
String String
char Character
byte Byte
short Short
int Integet
long Long
float Float
double Double
boolean Blooean
包装类和基本类的转换
基本数据类型->包装类
构造方法(参数为基本数据类型或字符串)
Integer intValue = new Integer(21);
Integer intValue = new Integer("21");
(Character除外)
包装类的静态重载的valueOf方法
Integer intValue = Intege.valueOf(21);
Integer intValue = Intege.valueOf("21");
(Character除外)
包装类->基本数据类型
typeValue();type为基本类型
Integer a= Intege.valueOf(21);
int b= a.intValue();
基本数据类型->字符串
String str = 包装类型.toString(基本类型)
String str = 基本数据变量+“”;
其他数据类型->字符串
String str = String.valueOf(Xxx/xxx arg);
字符串->基本数据类型
Xxx.parseXxx(String str)
包装类和基本类型自动转换
装箱:基本类型转换为包装类 Integer a = 5;
拆箱:包装类转换为基本类型 int b = a;