包装类####
概念:
基本类型对应的引用类型,默认值为null,实际上是一个持有了基本属性的、常量、转型方法的储存空间。
转换时注意类型兼容
Number转型方法
byte → Byte → 引用类型.byteVolue();
short → Short → 引用类型.shortVolue();
int → Integre → 引用类型.intValue();
long → Long → 引用类型.longValue
float → Float → 引用类型.floatValue();
double → Double → 引用类型.doubleValue();
静态转换方法:
parse八种基本类型(String s); 如下:
Byte B = Byte.parseByte(“123”);
Short S = Short.parseShort(“123”);
Integer I = parseInt(“123”);
Long L = parseLong(“123”);
Float F = parseFloat(“123”);
Double D = parseDouble(“123”);
Char C = parseChar(“123”);
Boolean B = parseBoolean(“123”);
valueOf(基本类型/字符串类型); //八种基本数据类型均可使用
Byte B = Byte.valueOf((Byte)123);
Byte B = Byte.valueOf(“123”);
自动拆箱、装箱: //JDK1.5以上版本可用:
Byte B = 10; //自动装箱
byte b = B; //自动拆箱
自动装、拆箱时会自动调用valueOf()方法,整数包装类型将常用256个数字提前创建并保存在数组中,用于提供对应缓冲区,区间复用时已有对象,区间外创建新对象与堆中。