标签:style class blog c code java
如果可变字符串操作较多的话,用STRINGBUILDER显然优势得多。
public class HelloJava { public static void main(String[] args) { // TODO Auto-generated method stub String str = "a"; 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 is " + time); System.out.println(str); StringBuilder builder = new StringBuilder("b"); starTime = System.currentTimeMillis(); for(int j = 0; j<10000;j++){ builder = builder.append(j); } endTime = System.currentTimeMillis(); time = endTime - starTime; System.out.println("StringBuilder time is " + time); System.out.println(builder); } }
JAVA中,字符串STRING与STRINGBUILDER的效率差异,布布扣,bubuko.com
JAVA中,字符串STRING与STRINGBUILDER的效率差异
标签:style class blog c code java
原文地址:http://www.cnblogs.com/aguncn/p/3747194.html