Yeah, it is true! But when you concatenate in loop the behaviour differs. e.g.
String str = "Some string";
for (int i = 0; i < 10; i++) {
str += i;
}
new StringBuilder
will be constructed at every single loop iteration (with initial value of str) and at the end of every iteration there will be concatenation with initial String (actually StringBuilder
with initial value of str
).
So you need to create StringBuilder by yourself only when you work with String concatenation in loop.