String 的 concat() 方法注释为:
Concatenates the specified string to the end of this string.
If the length of the argument string is 0, then this String object is returned. Otherwise, a String object is returned that represents a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
意思为可以将参数字符串拼接到字符串对象的后面
于是我写了一个例子
String url = "aaa"
url.concat("bbb")
System.out.print(url);
显示结果却还是"aaa"
又测试了一下
String url = "aaa"
System.out.print(url.concat("bbb"));
显示结果正常了,为"aaabbb"
突然就懂了,因为String类型为final的,定以后不可以被改变,而concat()方法也仅仅是执行后的result是拼接后的字符串,原来的字符串“aaa”则不会改变