public class StringBuilderDemo {
public static void main(String[] args) {
String str="s";
long startTime=System.currentTimeMillis();
for (int i = 0; i <10000 ; i++) {
str+=i;
}
long endTime=System.currentTimeMillis();
long time=endTime-startTime;
System.out.println("String消耗时间:"+time);
StringBuilder builder=new StringBuilder("s");
startTime=System.currentTimeMillis();
for (int i = 0; i <1000 ; i++) {
builder.append(i);
}
endTime=System.currentTimeMillis();
time=endTime-startTime;
System.out.println("StringBuilder消耗时间:"+time);
}
}