char a = 'h'; //类包装器 Character aobj = a ;//自动装箱 byte b = 6; Byte bobj = b; short s = 234; Short sobj = s; boolean b = true; Boolean bobj = b; int i = 100; Integer iobj = i; long l = 567L; Long lobj = l; float f = 8.99F; Float fobj = f; double d = 4.
在程序设计中经常用到一系列的数据类型,在Java中也一样包含八中数据类型,这八种数据类型又各自对应一种包装器类型.如下表: 基本类型 包装器类型 boolean Boolean char Character int Integer byte Byte short Short long Long float Float double Double 为什么存在这两种类型呢? 我们都知道在Java语言中,new一个对象存储在堆里,我们通过堆栈中的引用来使用这些对象:但是对于经常用到的一系列类型如int
基本类型的对象包装,也就是将常用的基本数据类型包装成对象 byte Byte short Short int Integer long Long boolean Boolean float Float double Double char Character 最常用的作用就是基本数据类型与字符串的转换 1. 基本数据类型转字符串: 基本数据类型+"" 基本数据类型类.toString(基本类型的数值) 2.字符串转成基本数据类型: Integer.parseInt() Long.par