privatestaticvoidtestString(){ long start = System.currentTimeMillis(); String str = ""; for (int i = 0; i < NUM; i++) { str += i; } long end = System.currentTimeMillis(); System.out.println("String:" + (end - start) + "ms"); }
privatestaticvoidtestStringBuffer(){ long start = System.currentTimeMillis(); StringBuffer str = new StringBuffer(); for (int i = 0; i < NUM; i++) { str.append(i); } long end = System.currentTimeMillis(); System.out.println("StringBuffer:" + (end - start) + "ms"); }
privatestaticvoidtestStringBuilder(){ long start = System.currentTimeMillis(); StringBuilder str = new StringBuilder(); for (int i = 0; i < NUM; i++) { str.append(i); } long end = System.currentTimeMillis(); System.out.println("StringBuilder:" + (end - start) + "ms"); } }