, .
.
:
1
. , ,
String concatenation = "a" + "b" + "c";
String concatenation = "abc";
1 .
2
StringBuilder StringBuffer.
,
String a;
String b;
String c;
String d;
String e;
String concat = a + b + c + d + e;
- java-:
String a;
String b;
String c;
String d;
String e;
String concat = new StringBuilder(a).append(b).append(c).append(d).append(e).toString();
6 : a, b, c, d, e , a + b + c + d + e
3
StringBuilder , ,
String a;
String b;
String c;
String concat = a + b + c;
-, java-
String a;
String b;
String c;
String concat = a.concat(b).concat(c);
java- -:
public String concat(String str) {
int otherLen = str.length();
if (otherLen == 0) {
return this;
}
char buf[] = new char[count + otherLen];
getChars(0, count, buf, 0);
str.getChars(0, otherLen, buf, count);
return new String(0, count + otherLen, buf);
}
concat, String. 5 : a, b, c, a + b a + b + c
Note. any other compiler can choose another internal optimization from source code to compiled code. What you need to know is that in the worst case you will have 1 line generation for each start line and 1 line for each concatenation (each +). So, if you have 3 lines combined with two concatenation operations, you will have a maximum of 5 lines.