The idea of ββusing StringBuffer or StringBuilder is to avoid re-concatenating strings as shown below:
String result = ""; for (int i = 0; i < 200; i++) { result = result + i + ","; }
This is inefficient, in each loop one String object is created (created by java)
Using StringBuilder / StringBuffer:
StringBuilder buf = new StringBuilder(200); // init with a estimation of length has advantage for (int i = 0; i < 200; i++) { buf.append(i).append(","); } String result = buf.toString();
This avoids the unnecessary creation of lines in each cycle, it simply fills the buffer with characters and, if necessary, changes the size of the buffer.
However, in your case it is not worth the effort.
source share