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 new String object is created, representing 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.
Examples:
"cares".concat("s") returns "caress"
"to".concat("get").concat("her") returns "together"
Parameters:
str the String that is concatenated to the end of this String.
Returns:
a string that represents the concatenation of this object's characters followed by the string argument's characters.
public class TestConcat {
public static void main(String[] args) {
String str1 = "a";
String str2 = "b";
String str3 = str1.concat(str2);
System.out.println(str3);
}
}
输出结果:ab