How to concatenate String in Java

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×

In java we can concatenate string using the concat method of the java.lang.String class. Concat method appends the input string to the current string and returns the combined string.

Above code concatenates two strings – merges into a single string. This is not efficient when you have many strings to be concatenated in a dynamic fashion. In such situations it is better to use StringBuffer class. StringBuffer has append method, that does exactly the same thing without out creating intermediate strings. Hence from a performance point of view, it is better to use StringBuffer class.