Usage of concat in Java
The concat() method is a method in the String class and is used to concatenate two strings. It returns a new string that is the result of concatenating the two original strings.
Syntax
<code class="java">public String concat(String str)</code>
Parameters
str
- The string to be concatenatedReturn value
The new string after concatenation
Usage method
concat( ) method is used to concatenate two strings into a new string. It can be used in the following ways:
<code class="java">String str1 = "Hello"; String str2 = "World"; String newStr = str1.concat(str2); System.out.println(newStr); // 输出:HelloWorld</code>
In the above example, str1
and str2
are concatenated into a new string newStr
, the value of this string is "HelloWorld".
Note
str
parameter is null, a "null" string will be generated. 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!