日期:2014-05-20 浏览次数:20762 次
public class Test {
public static void main(String[] args) {
final int SIZE = 10000;
long start = 0;
String str = new String();
start = System.currentTimeMillis();
for (int i = 0; i < SIZE; i++)
str += "aba"+i;
System.out.println(System.currentTimeMillis() - start);
String str2 = new String();
start = System.currentTimeMillis();
for (int i = 0; i < SIZE*100; i++)
str2.concat("abc"+i);
System.out.println(System.currentTimeMillis() - start);
StringBuffer sb = new StringBuffer();
start = System.currentTimeMillis();
for (int i = 0; i < SIZE*100; i++)
sb.append("abd"+i);
System.out.println(System.currentTimeMillis() - start);
StringBuilder sbu = new StringBuilder();
start = System.currentTimeMillis();
for (int i = 0; i < SIZE*100; i++)
sbu.append("abe"+i);
System.out.println(System.currentTimeMillis() - start);
}
}