也行你知道,也许你不知道
一:
@Test
public void test() {
long start = System.currentTimeMillis();
String str = "";
for(int i = 0 ; i < 499990 ;i++){
str = str+i;
}
long end = System.currentTimeMillis();
System.out.println(start);
System.out.println(end);
System.out.println((double)(end-start)/1000);
}
1335404638171
1335406659968
2021.797
二:
@Test
public void test2() {
long start = System.currentTimeMillis();
StringBuffer str = new StringBuffer();
for(int i = 0 ; i < 499999 ;i++){
str.append(i);
}
long end = System.currentTimeMillis();
System.out.println(start);
System.out.println(end);
System.out.println((double)(end-start)/1000);
}
1335406936015
1335406936140
0.125
三:
@Test
public void test2() {
long start = System.currentTimeMillis();
StringBuffer str = new StringBuffer();
for(int i = 0 ; i < 1999999 ;i++){
str.append(i);
}
long end = System.currentTimeMillis();
System.out.println(start);
System.out.println(end);
System.out.println((float)(end-start)/1000);
}
1335409426250
1335409426593
0.343
这下,你知道了吧