Java String concatThe 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. SignatureThe signature of the string concat() method is given below: ParameteranotherString : another string i.e., to be combined at the end of this string. Returnscombined string Internal implementationJava String concat() method exampleFileName: ConcatExample.java Test it NowOutput: java string java string is immutable so assign it explicitly Java String concat() Method Example 2Let's see an example where we are concatenating multiple string objects. FileName: ConcatExample2.java Output: HelloJavatpoint HelloJavatpointReader Java String concat() Method Example 3Let'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">[email�protected]</a> Java String concat() Method Example 4Till 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 Next TopicJava String contains() |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India