package test;
public class Demo {
public static void main(String[] args) {
String str = "";
long starTime = System.currentTimeMillis();//获取时间
for(int i=0;i<10000;i++){
str = str + i;
}
long endtime = System.currentTimeMillis();
long time = endtime-starTime;
System.out.println("String消耗的时间:"+time);
StringBuffer sbf = new StringBuffer();
starTime = System.currentTimeMillis();//获取时间
for(int i=0;i<10000;i++){
sbf.append(i);
}
endtime = System.currentTimeMillis();
time = endtime-starTime;
System.out.println("StringBuffer消耗的时间:"+time);
StringBuilder sbd = new StringBuilder();
starTime = System.currentTimeMillis();//获取时间
for(int i=0;i<10000;i++){
sbd.append(i);
}
endtime = System.currentTimeMillis();
time = endtime-starTime;
System.out.println("StringBuilder消耗的时间:"+time);
}
}