Possible Duplicate:
java String concatenation
Sources tell us that concat
is implemented as follows:
public String concat(String str) {
int otherLen = str.length();
if (otherLen == 0) {
return this;
}
int len = value.length;
char buf[] = Arrays.copyOf(value, len + otherLen);
str.getChars(buf, len);
return new String(buf, true);
}
Does +
implementation differ when it comes to Strings? How? Is there a performance difference between +
and concat
. When should one be chosen over another?