日期:2014-05-20 浏览次数:21303 次
long startTime = System.currentTimeMillis();
String aaa = "aaa";
String ccc = "ccc";
String ddd = "ddd";
String eee = "ddd";
String fff = "ddd";
String ggg = "ddd";
String hhh = "ddd";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000000; i++) {
sb.append(aaa);
sb.append("accc");
sb.append(ccc);
sb.append("vvvc");
sb.append(ddd);
sb.append(eee);
sb.append(fff);
sb.append(ggg);
sb.append(hhh);
sb.delete(0, sb.length());
}
//1.................
System.out.println(System.currentTimeMillis() - startTime);
try {
Thread.sleep(1000);
}
catch (InterruptedException e1) {
e1.printStackTrace();
}
startTime = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++) {
String acc = aaa+"accc"+ccc+"vvvc"+ddd+eee+fff+ggg+hhh;
}
//2.................
System.out.println(System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
String add = "a";
for (int j = 0; j < 1000; j++) {
add += aaa;
}
}
//3.................
System.out.println(System.currentTimeMillis() - startTime);
public class Example {
public static void main(String[] args) {
String aaa = "aaa";
String ccc = "ccc";
String ddd = "ddd";
String eee = "ddd";
String fff = "ddd";
String ggg = "ddd";
String hhh = "ddd";
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++) {
String acc = aaa+"accc"+ccc+"vvvc"+ddd+eee+fff+ggg+hhh;
}
System.out.println(System.currentTimeMillis() - startTime);
}
}