包装类

Java 为每个基本数据类型都提供了一个包装类, 这样我们就可以像操作对象那样来操作基本数据类型.

包装类主要提供了两大类方法:

  • 将本类型和其他基本类型进行转换的方法

  • 将字符串和本类型及包装类互相转换的方法

以 Integet 为例, 其它类似

Integer n1 = new Integer(5);
Integet n2 = new Integer(“5”);

JDK1.5 中引入了自动装箱拆箱的机制

Last updated