If you use Stringconcatenation in a loop (something like:
String s ="";
for(int i = 0; i <100; i++) {
s += ", " + i;
}
then you should usea StringBuilder (not StringBuffer)instead of a String, because it is much faster and consumes less memory.
If you have a singlestatement:
String s = "1," + "2, " + "3, " + "4, " ....;
then you can useStrings, because the compiler will use StringBuilder automatically.
Comments
Leave a comment