staticvoidtestString(){ long begin = System.currentTimeMillis(); String str = ""; for (int i = 0; i <= 10000; i++) { str += i; } long last = System.currentTimeMillis(); long res = last - begin; System.out.println(res); }
StringBuilder
1 2 3 4 5 6 7 8 9 10 11
staticvoidtestBuilder(){ long begin = System.currentTimeMillis(); StringBuilder str = new StringBuilder(); for(int i = 0; i <= 10000000; i++) { //str += i; str.append(i); } long last = System.currentTimeMillis(); long res = last -begin; System.out.println(res); }
StringBuffer
1 2 3 4 5 6 7 8 9 10 11
staticvoidtestBuffer(){ long begin = System.currentTimeMillis(); StringBuffer str = new StringBuffer(); for (int i = 0; i <= 10000000; i++) { //str += i; str.append(i); } long last = System.currentTimeMillis(); long res = last - begin; System.out.println(res); }