Java String concat() Method

String concatenation is the process of combining two or more small String to create a bigger String. In Java you can combine string in multiple ways. Using + operator is the easiest way of joining multiple String. Also you can use String.concat() method to joining two strings in Java. But to improve performance, instead of using + operator or String.concat(), use StringBuffer is better choice. All method of concatenating string is following:

Using + operator

You can concatenate Strings in Java using the + operator.

Above code will return "Java String Tutorial"



Using StringBuffer

In order to improve performance StringBuffer is the better choice.

The quickest way of concatenate two string using + operator.

The compiler translates this code as:

Main reason of performance drop is creation of lots of temporary String object due to immutability of String. Just remember that String concatenation using + operator is also converted to corresponding StringBuffer or StringBuilder call depending upon which version of Java you are using, because StringBuilder is only available from Java 1.5 . So the best approach is to use StringBuffer.

Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.


Using Java String concat() method

Java String Concat(String str) method concatenates the specified String to the end of this string.

 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About