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 OverflowW3Schools
w3schools.com โบ java โบ java_strings_concat.asp
Java Strings Concatenation
The + operator can be used between strings to combine them.
06:15
Concatenating Strings in Java - YouTube
07:09
Java Tutorial - 08 - Combining Strings (Concatenation) - YouTube
04:24
Concatenating (Joining) Strings in Java - YouTube
04:28
String Concatenation in Java | java string concatenation with numbers ...
05:07
How to join two or more Strings using the Java String concat() ...
11:32
String Concatenation In Java | Java Full Course From Scratch - YouTube
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
Top answer 1 of 7
17
It is better to use StringBuilder
StringBuilder sb = new StringBuilder();
for(String tempString:setInput){
sb.append(",").append(tempString).append(",");
}
2 of 7
8
Or we can use Java 8 Stream
String joined = Stream.of("A", "B", "C").collect(Collectors.joining("delimiter", "prefix", "suffix"));
Or use the StringJoiner class
Directly Use StringJoiner class
Or the StringBuilder class
new StringBuilder().add("A").add("B").toString()
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.
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....
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.