一、基本数据类型与其对应的封装类之间的相互转换
1.基本数据类型转换为封装类
有三种方法:
a.直接赋值 (自动装箱)
c.使用封装类提供的valueOf()方法(静态方法)
2.封装类转换为基本数据类型
有两种方法:
a.直接赋值(自动拆箱)
b.使用封装类提供的value()方法
二、基本数据类型与字符串之间的相互转换
1.基本数据类型转换为字符串
有三种方法:
a.使用String类的valueOf()方法(静态方法)
b.使用封装类的toString()方法(静态方法)
c.使用字符串连接符“+”
2.字符串转换为基本数据类型
有一种方法:
a.使用封装类的静态方法
三、封装类与字符串之间的相互转换
1.字符串转换为封装类
有两种方法:
a.使用封装类的含参构造方法(实例化)
b.使用封装类的valueOf()方法
2.封装类转换为字符串
有三种方法:
a.使用字符串连接符“+”
b.使用封装类的toString()方法
c.使用String类的valueOf()方法
四、总结
以上所列都是基本数据类型、封装类和字符串两两之间的直接转换,因此,可以衍生出来一些其他的东西,类似数学中的等量代换吧
举例说明:
这两行代码中,封装类Integer的toString方法要求的参数是基本数据类型int,但是变量i是int的封装类,所以这里就有一个把Integer转换为int的过程,即自动装箱
http://blog.csdn.net/feiyudiaoling/article/details/51354413