Java中的数据类型

图1.java数据类型
基本数据类型的问题:
1.不具备对象的特征
2.无法进行对象化交互
解决办法:包装类
包装类与基本数据类型

图2.包装类与基本数据类型对照
装箱:把基本数据类型转换为包装类
自动装箱:int t1 = 2; Integer t2 = t1;
手动装箱:Integer t3 = new Integer(2);
拆箱:把包装类转换成基本数据类型
自动拆箱: Integer t2 =2; int t4 = t2;
手动拆箱:int t5 = t2.intValue();
字符串与基本数据类型
基本数据类型转换为字符串
使用包装类的同toString()方法
int t1=2;
String t2 = Integer.toString(t1);
字符串转换为基本数据类型
自动拆箱调用包装类的 parseXxx() 静态方法
String t2 ="2222";
int t3=Integer.parseInt(t2);
调用包装类的 valueOf() 方法转换为基本类型的包装类, 自动拆箱
String t2 ="2222";
int t4 = Integer.valueOf(t2);