The concat() method in Java is used to append another string to the end of an existing string to create a new string. Specific usage includes: splicing multiple strings. Adds fixed text to an existing string. Used in series.
Usage of concat()
in Java
concat()# The ## method is a built-in method of the
String class in Java and is used to append another string to the end of the existing string.
Syntax:
<code class="java">public String concat(String str)</code>
Parameters:
- To be appended to the current There are strings of strings.
Return value:
Usage:
concat() method can be used in the following scenarios:
<code class="java">String str1 = "Hello"; String str2 = "World"; String result = str1.concat(str2); //结果为 "HelloWorld"</code>
<code class="java">String str = "This is "; String addition = "a test"; String result = str.concat(addition); //结果为 "This is a test"</code>
<code class="java">String str1 = "John"; String str2 = "Doe"; String result = "Name: ".concat(str1).concat(" ").concat(str2); //结果为 "Name: John Doe"</code>
Note:
method creates a new string. It does not modify existing strings.
is
null,
concat() will generate a
"null" string.
Performs efficient string concatenation on immutable strings.
The above is the detailed content of How to use concat in java. For more information, please follow other related articles on the PHP Chinese website!