It is better to use StringBuilder

StringBuilder sb = new StringBuilder();

for(String tempString:setInput){
    sb.append(",").append(tempString).append(",");   
}
Answer from Ruchira Gayan Ranaweera on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ concatenate-multiple-strings-in-java
How to Concatenate Multiple Strings in Java? - GeeksforGeeks
July 23, 2025 - Now we will explain each method with examples in Java. ... This is an approach for concatenating multiple Strings in Java, This StringBuilder class provides one method which is append() method.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ concatenating strings in java
Concatenating Strings in Java | Baeldung
May 8, 2025 - Internally, StringBuilder maintains a mutable array of characters. In our code sample, weโ€™ve declared this to have an initial size of 100 through the StringBuilder constructor. Because of this size declaration, the StringBuilder can be a very efficient way to concatenate Strings.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-string-concat-examples
Java String concat() Method with Examples - GeeksforGeeks
The concat() method in Java is used to append one string to another and returns a new combined string. It does not modify the original string since strings are immutable. ... class GFG { public static void main(String args[]) { // String ...
Published: April 7, 2026
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ concatenate multiple strings in java
Concatenate multiple strings in Java | Techie Delight
July 7, 2026 - This post will discuss how to concatenate multiple strings in Java using the + operator, String.concat() method, and append() method of the StringBuffer/StringBuilder class.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-concatenate-strings-in-java
How to concatenate strings in Java
StringBuilder class is an efficient way to concatenate strings in Java. It allows us to modify strings without creating intermediate string objects. We can use the StringBuilder class to create the first string and then append it to another string using the append() method...
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ strings in java โ€บ string concatenation in java
String Concatenation in Java
April 1, 2025 - I learn concatenation in Java CodeGym.cc/quest I have got it I haven't got it Itโ€™s important to know that the concat() method doesnโ€™t change the string, but creates a new one as a result of merging the current one and the one passed as a parameter.
Find elsewhere
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 05 โ€บ 4-ways-to-concatenate-strings-in-java.html
4 ways to concatenate Strings in Java [Example and Performance] | Java67
Anyway, this article is not just about + operator but also about other ways to concatenate multiple Strings. There are four ways to do this, apart from the + operator, we can use StringBuffer, StringBuilder, and concat() method from java.lang.String ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ Concatenate-Multiple-Strings-in-Java
Concatenate Multiple Strings in Java.
February 26, 2020 - You can concatenate multiple strings using the โ€˜+โ€™ operator of Java.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ string concatenation in java
String Concatenation in Java | Baeldung
January 8, 2024 - First, we have the StringBuilder class. This class provides the append() method to perform concatenation operations.
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ java-string-concatenation
Java String concat() Method with Examples - TechVidvan
February 17, 2025 - Concatenation is combining two or more strings to form a new string by appending the next string to the end of the previous strings. In Java, two strings can be concatenated using the + or += operator or the concat() method, defined in the ...
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2015 โ€บ 01 โ€บ 3-examples-to-concatenate-string-in-java.html
3 Examples to Concatenate String in Java
For example, you can create a full name by concatenating first and last name of a person. Java provides multiple ways to concatenate String, but the easiest of them is by using + operator.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2013 โ€บ 12 โ€บ java-string-concat-method-example
Java String concat() Method example
September 11, 2022 - public class ConcatenationExample ... is").concat(" just a").concat(" String"); System.out.println(str2); } } ... As we have seen above that concat() method appends the string at the end of the current string....
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_concat.asp
Java String concat() Method
Java Examples Java Videos Java ... System.out.println(firstName.concat(lastName)); ... The concat() method appends (concatenate) a string to the end of another string....
๐ŸŒ
Alvin Alexander
alvinalexander.com โ€บ blog โ€บ post โ€บ java โ€บ combine-two-strings
Java String concatenation: How to combine (merge) two Strings | alvinalexander.com
March 29, 2024 - // define two strings String firstName = "Fred"; String lastName = "Flinstone"; // concatenate the strings String fullName = firstName + lastName; The string fullName now contains "FredFlinstone". Note that there is no space between "Fred" and "Flinstone" because I didnโ€™t put a space in there. One way to add a space to the new string is to put one in there, as shown in this example: String firstName = "Fred"; String lastName = "Flinstone"; String fullName = firstName + " " + lastName;
๐ŸŒ
Medium
medium.com โ€บ @nagarjun_nagesh โ€บ maximizing-performance-in-java-string-concatenation-c588a7a125e8
Maximizing Performance in Java String Concatenation | by Nagarjun (Arjun) Nagesh | Medium
June 26, 2024 - While the + operator is convenient and readable for small-scale concatenation, using StringBuilder explicitly is recommended for scenarios involving concatenation of multiple strings, especially within loops or performance-sensitive code. By understanding these nuances and following best practices outlined in "Effective Java," developers can optimize string concatenation to improve application performance and efficiency.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-java-string-concatenation-117956
Mastering String Concatenation in Java | LabEx
Another way to concatenate strings in Java is by using the StringBuilder class. The StringBuilder class provides append() method to combine two or more strings. StringBuilder is faster than String class while concatenating strings.