Home >Java >javaTutorial >How to use concat in java

How to use concat in java

下次还敢
下次还敢Original
2024-05-08 03:42:151254browse

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 concatenated

Return 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

  • The concat() method does not modify the original string.
  • If the str parameter is null, a "null" string will be generated.
  • The concat() method can also be used to concatenate strings and other basic types (such as int, double), but these values ​​will be converted to 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn