包装类
包装类
| 序号 | 基本数据类型 | 包装类 |
|---|---|---|
| 1 | int | Integer |
| 2 | char | Character |
| 3 | float | Float |
| 4 | double | Double |
| 5 | boolean | Boolean |
| 6 | byte | Byte |
| 7 | short | Short |
| 8 | long | Long |
基本数据类型对应的包装类。
包装类也分为两大类型:
- Number:Integer、Short、Long、Double、Float、Byte都是Number的子类。
- Object:Character、Boolean都是Object的子类。
1.装箱、拆箱操作
将一个基本数据类型变为包装类,叫装箱操作;
将一个包装类变为一个基本数据类型,叫拆箱操作;
/**
* 测试类
* @author 孟祥宽
*
*/
public class Demo {
public static void main(String[] args) {
Book.Info info = new Book.Info();// 创建内部类对象
info.say();
byte small = 'a';
// 手动装箱
Byte big = new Byte(small);
// 手动拆箱
big.byteValue();
System.out.println(big.byteValue());
// 自动装箱
Integer integer = 200;
// 自动拆箱
int aint = integer;
}
}

浙公网安备 33010602011771号