基本类型转换为字符串有两种方法:
- 使用包装类的 toString() 方法
- 使用String类的 valueOf() 方法
Eg:
int a = 10;
①String b = Integer.toString(a);
②String b1 = String.valueOf(a);
将字符串转换成基本类型有两种方法:
- 调用包装类的 parseXxx 静态方法
- 调用包装类的 valueOf()方法转换为基本类型的包装类,会自动拆箱
String str = "aaaa";
①int a = Integer.parseInt(str);
②int a1 = Integer.valueOf(str);