string concat
字符串concat()方法 (String concat() Method)
concat() is a String method in Java and it is used to concatenate (add) a given string to the string. It returns a concatenated string.
concat()是Java中的String方法,用于将给定的字符串连接(添加)到字符串。 它返回一个串联的字符串。
Syntax:
句法:
String str_object.concat(String str);
Here,
这里,
str is a String object to be added.
str是要添加的String对象。
str_object is the main string in which we have to add/concatenate str.
str_object是必须在其中添加/连接str的主要字符串。
Method returns a concatenated string at the end of the str_object.
方法在str_object的末尾返回一个串联的字符串。
Example:
例:
Input:
str1 = "Hello"
str2 = "world!"
Function call:
str1.concat(str2);
Output:
"Helloworld!"
Java code to concatenate the string using String.concat() method
Java代码使用String.concat()方法连接字符串
public class Main
{
public static void main(String[] args) {
String str1 = "Hello";
String str2 = "world!";
//adding str2 to the str1
String str3 = str1.concat(str2);
//printing values
System.out.println("str1 = " + str1);
System.out.println("str2 = " + str2);
System.out.println("str3 = " + str3);
}
}
Output
输出量
str1 = Hello
str2 = world!
str3 = Helloworld!
翻译自: https://www.includehelp.com/java/string-concat-method-with-example.aspx
string concat