String concatenation is implemented through the StringBuffer class and its append method.也就是说在java内部的确是对+进行了重载,在处理String的过程中要创建一个StringBuffer对象,用StringBuffer对象的append方法对字符串进行连接,最后调用toString方法返回String字符串。
String s = "a " + "b " + "c ";
就等于String s = "abc ";
String a = "a ";
String b = "b ";
lss很透彻。
String c = "c ";
String s = a + b + c;
这个就不一样了,好像最终结果类似于:
StringBuffer temp = new StringBuffer();
temp.append(a).append(b).append(c);
String s = temp.toString(); |