Java String concat() Method Explained
The concat method in Java is used to join one string with another string, resulting in a new string. This method is defined in the String class, and can be used as follows:
String str1 = "Hello";
String str2 = "World";
String result = str1.concat(str2);
System.out.println(result); // 输出:HelloWorld
The concat method appends the str2 string to the end of the str1 string, resulting in a new string “HelloWorld”. It is important to note that the concat method does not modify the original strings but instead returns a new string, so it is necessary to assign the return value to a new variable when using it.