【发布时间】:2011-07-13 12:39:16
【问题描述】:
我可以使用将整数转换为字符串
String s = "" + 4; // correct, but poor style
or
String u = Integer.toString(4); // this is good
我可以使用将双精度数转换为字符串
String s = "" + 4.5; // correct, but poor style
or
String u = Double.toString(4.5); // this is good
我可以使用String s = "" + dataapproach 将int 或double 转换为String。如果我想使用 toString() 的其他方法,我必须使用每种数据类型的 Wrapper 类。那么为什么在some books 中提到第一种方法很差,而第二种方法更好。 哪种方法更好?为什么?
【问题讨论】:
标签: java