啥也不說了,直接代碼,別人的,我試的,哈哈:
/**
* 測試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));
}