啥也不说了,直接代码,别人的,我试的,哈哈:
/**
* 测试StringValueOf
* 2015年3月20日 wenzibin1 新建
*/
public static void testStringValueOf() {
long t = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
String s0 = String.valueOf(11);
}
System.out.println("耗时" + (System.currentTimeMillis() - t));
t = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
String s = "" + 11;
}
System.out.println("耗时" + (System.currentTimeMillis() - t));
String str = "";
t = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
String s = str + 11;
}
System.out.println("耗时" + (System.currentTimeMillis() - t));
}