//判断字符串为空:
//使用String类声明字符串变量时,将其初始换为null,此时可以使用关系运算符“==”进行判断
//使用String类声明字符串变量时,为其指定0长度的空字符串,此时可以使用equals()方法或使用length()方法进行判断
public class Jerque {
public static void main(String[] args){
String str="";
long starTime=System.currentTimeMillis();
for(int i=0;i<100000;i++){
str=str+i;
}
long endTime=System.currentTimeMillis();
long time=endTime-starTime;
System.out.println("String小号的时间:"+time);
StringBuilder builder=new StringBuilder("");
starTime=System.currentTimeMillis();
for (int j=0;j<100000;j++){
builder.append(j);
}
endTime=System.currentTimeMillis();
time=endTime-starTime;
System.out.println("StringBuild消耗的时间:"+time);
}
}
运行结果