Home » Java String concat() method

Java String concat() method

by Online Tutorials Library

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:

HelloTutoraspire  HelloTutoraspireReader  

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 TutorAspire Reader  Hello!!!  <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afe7cac3c3c0efe5ced9cedbdfc0c6c1db">[email protected]</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  

You may also like