package 实训;
public class 实训9lichenglong {
public static void main(String[] args) {
// TODO 自动生成的方法存根
String a ="";//创建空的字符串
String s ="";
String d ="水牛";
long starTime =System.currentTimeMillis();//定义对字符串执行操作的起始时间
for(int i=0;i<10000;i++) {//利用for循环执行1000次操作
a +=d;//循环追加字符串
}
long endTime =System.currentTimeMillis();//定义字符串操作后的时间
long f =endTime-starTime;//计算对字符串执行操作的时间
System.out.println("+=消耗时间:"+f);//将执行的时间输出
starTime = System.currentTimeMillis();//更行操作执行前的时间
for(int j=0;j<10000;j++) {//利用for循环叠加
s=s.concat(d);//拼接字符串
}
endTime =System.currentTimeMillis();//更新操作后的时间
long time = endTime -starTime;//更新追加操作执行时间
System.out.println("concat()消耗时间:"+time);//将操作时间输出
if(f>time) { //判断
System.out.println("concat()时间更短");
}
else
{System.out.println("+=时间更短");
}
}
}