8种基本数据类型:
整数型:byte short int long
浮点型:float double
字符型:char
布尔型:boolean
8种数据类型对应的包装类:
byte | Byte |
short | Short |
int | Integer |
long | Long |
char | Charactor |
float | Float |
double | Double |
boolean | Boolean |
1.基本数据类型→包装类,调用包装类构造 int a = 10; Integer b = new Integer(a);
2.包装类→基本数据类型, 调用包装类对象的**value(), Integer b = new Integer(10); int a = b.intValue();
3.包装类→String,调用包装类的对象的toString(), Intger b = new Integer(10); String str = b.toString();
4.String→包装类,调用包装类的构造方法, String str = "10"; Integer b = new Integer(str);
5.String→基本数据类型,包装类.valueOf(), int b = Integer.valueOf(str); 或者是 Integer.parseInt(str)
6.基本数据类型→String,调用包装类的toString(); String str = Integer.toString(10); 或者 str = 10+"";
7.String转换char数组,使用toString(), String str = "hello world"; char[] charArray = str.toString();
8.char数组转换String, char[] charArray = {'h','e','l','l','o'....}; str = new String(charArray);
9。Integer a = 10; 自动封箱
int b = a; 自动拆箱