一: 将整数 int 转换成字串 String
int num=666;
String str="";
str= num+""; //第一种方法:会产生两个String对象
str= String.valueOf(num); //第二种方法:直接使用String类的静态方法,只产生一个对象
二: 将字符串 String 转换成整数 int
String str="666";
int num;
num=Integer.parseInt(str);//第一种方法:直接使用静态方法,不会产生多余的对象,但会抛出异常
num=Integer.valueOf(str).intValue();//第二种方法:Integer.valueOf(str) 相当于 new Integer(Integer.parseInt(str)),也需要抛异常,还会多产生一个对象
原文:https://www.cnblogs.com/jiehao-yu/p/14890889.html