针对八种基本定义相应的引用类型——包装类(封装类)
有了类的特点,就可以调用类中的方法
基本数据类型 包装类
boolean Boolean
byte 、Byte
short Short
int Integer
long Long
char Character
float Float
double Double
基本数据类型包装成包装类的实例--装箱
通过包装类的构造器实现:
public class Main {
public static void main(String[] args) {
int i = 10;
Integer t = new Integer(i);//手工装箱
Integer a =10;//自动装箱
System.out.println("a="+a);
}
}
还可通过字符串参数构造包装类对象:
Float f = new Float("4.12");
Long l = new Long("asde");//numberFormatException
获得包装类对象中包装的基本类型变量--拆箱
调用包装类的。xxxValue()方法:
boolean b = b 对象。方法
JDK1.5之后,支持自动装拆,但类型必须匹配