Javatpoint Logo
Javatpoint Logo

Java String concat

The Java String class concat() method combines specified string at the end of this string. It returns a combined string. It is like appending another string.

Signature

The signature of the string concat() method is given below:

Parameter

anotherString : another string i.e., to be combined at the end of this string.

Returns

combined string

Internal implementation

Java String concat() method example

FileName: ConcatExample.java

Test it Now

Output:

java string
java string is immutable so assign it explicitly

Java String concat() Method Example 2

Let's see an example where we are concatenating multiple string objects.

FileName: ConcatExample2.java

Output:

HelloJavatpoint
HelloJavatpointReader

Java String concat() Method Example 3

Let's see an example where we are concatenating spaces and special chars to the string object. It is done using the chaining of the concat() method.

FileName: ConcatExample3.java

Output:

Hello Javatpoint Reader
Hello!!!
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afe7cac3c3c0efe5ced9cedbdfc0c6c1db">[emailprotected]</a>

Java String concat() Method Example 4

Till now, we have seen that the concat() method appends the string at the end of the string that invokes the method. However, we can do a bit of workaround to append the string at the beginning of a string using the concat() method.

FileName: ConcatExample4.java

Output:

India is my Country






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA