You can try this:
StringUtils.join(mylist, ',');
See org.apache.commons.lang3.StringUtils.
Answer from Rahul Tripathi on Stack OverflowDZone
dzone.com › coding › java › convert a list to a comma-separated string in java 8
Convert a List to a Comma-Separated String in Java 8 - DZone
June 29, 2016 - private static final String SEPARATOR = ","; public static void main(String[] args) { List<String> cities = Arrays.asList( "Milan", "London", "New York", "San Francisco"); StringBuilder csvBuilder = new StringBuilder(); for(String city : cities){ csvBuilder.append(city); csvBuilder.append(SEPARATOR); } String csv = csvBuilder.toString(); System.out.println(csv); //OUTPUT: Milan,London,New York,San Francisco, //Remove last comma csv = csv.substring(0, csv.length() - SEPARATOR.length()); System.out.println(csv); //OUTPUT: Milan,London,New York,San Francisco } As you can see it’s much more verb
Baeldung
baeldung.com › home › java › java string › convert a list to a comma-separated string
Convert a List to a Comma-Separated String | Baeldung
July 2, 2025 - List conversion is still a hot topic as it’s something that we do very often as Java developers. In this tutorial, we’ll learn how to convert a List of String to a comma-separated String using four different approaches. We’ll use three different classes and their methods, available since Java 8, for conversion.
Kokaruk
kokaruk.com › 2017 › 09 › 15 › quickly-convert-list-of-ints-to-string-using-streams
Convert a List of Integers to a comma separated string · class Rock implements Throwable
August 23, 2020 - Originally published on 2017-09-14 Java List interface doesn’t have a method to join all members to coma separated string. Previous versions required iterating over the list and appending and instance of Stringbuilder. Using Java 8 Streams makes it more neat. https://gist.github.com/rmit-s3668804-Dzmitry-Kakaruk/7cb0f29c147cfb99e503f504ba3787f5
Reverse Coding
reversecoding.net › java-8-convert-list-string-comma
Java 8 - Convert List to String comma separated | Reverse Coding
May 22, 2016 - private static final String SEPARATOR = ","; public static void main(String[] args) { List<String> cities = Arrays.asList( "Milan", "London", "New York", "San Francisco"); StringBuilder csvBuilder = new StringBuilder(); for(String city : cities){ csvBuilder.append(city); csvBuilder.append(SEPARATOR); } String csv = csvBuilder.toString(); System.out.println(csv); //OUTPUT: Milan,London,New York,San Francisco, //Remove last comma csv = csv.substring(0, csv.length() - SEPARATOR.length()); System.out.println(csv); //OUTPUT: Milan,London,New York,San Francisco · As you can see it’s much more ver
GeeksforGeeks
geeksforgeeks.org › java › convert-a-list-of-string-to-a-comma-separated-string-in-java
Convert a List of String to a comma separated String in Java - GeeksforGeeks
January 23, 2026 - delimiter: The string used to separate elements (, in this case) ... import java.util.*; public class GFG { public static void main(String args[]) { List<String> list = new ArrayList<>(Arrays.asList("Geeks", "ForGeeks", "GeeksForGeeks")); System.out.println("List of String: " + list); String result = String.join(",", list); System.out.println("Comma separated String: " + result); } }
TutorialsPoint
tutorialspoint.com › article › java-program-to-convert-a-list-of-string-to-comma-separated-string
Java program to convert a list of string to comma separated string
August 26, 2025 - Original List: [Java, Python, JavaScript, C++, Swift] Comma-Separated String: Java, Python, JavaScript, C++, Swift · In Java 8 and later, we can use the method Collectors.joining() from the Streams API to convert a list of strings to a ...
javaspring
javaspring.net › blog › java-list-to-comma-separated-string
Converting Java List to Comma-Separated String — javaspring.net
Converting a Java List to a comma-separated string is a common operation with multiple approaches. Each method has its own advantages and disadvantages. The for loop is the most basic and straightforward, but it may not be the most efficient. StringBuilder is more efficient for large lists. Java 8 Stream API offers a concise and functional way to achieve the conversion, and Apache Commons Lang provides a convenient utility method.
TutorialsPoint
tutorialspoint.com › convert-a-list-of-string-to-a-comma-separated-string-in-java
Convert a List of String to a comma separated String in Java
import java.util.*; public class Demo { public static void main(String args[]) { List<String> myList = new ArrayList<>(Arrays.asList("One", "Two", "Three", "Four")); System.out.println("List = " + myList); // comma separated String str = String.join(", ", myList); System.out.println("String (Comma Separated) = " + str); } }
Top answer 1 of 3
508
Since Java 8:
String.join(",", slist);
From Apache Commons library:
import org.apache.commons.lang3.StringUtils
Use:
StringUtils.join(slist, ',');
Another similar question and answer here
2 of 3
10
You could count the total length of the string first, and pass it to the StringBuilder constructor. And you do not need to convert the Set first.
Set<String> abc = new HashSet<String>();
abc.add("A");
abc.add("B");
abc.add("C");
String separator = ", ";
int total = abc.size() * separator.length();
for (String s : abc) {
total += s.length();
}
StringBuilder sb = new StringBuilder(total);
for (String s : abc) {
sb.append(separator).append(s);
}
String result = sb.substring(separator.length()); // remove leading separator
Javathinking
javathinking.com › blog › convert-list-of-object-to-comma-separated-string-java-8
Converting a List of Objects to a Comma-Separated String in Java 8 | JavaThinking.com
July 9, 2025 - A stream represents a sequence of elements and supports various operations like filtering, mapping, and reducing. To convert a list of objects to a comma - separated string, we can use the Collectors.joining() method which is a terminal operation that concatenates the elements of a stream into ...
Stack Overflow
stackoverflow.com › questions › 56183405 › converting-list-of-long-values-to-comma-separated-along-with-paranthesis-around
java - Converting List of long values to comma separated along with paranthesis around the each value - Stack Overflow
List<String> originalList = new ArrayList<String>(); originalList.add("1234567"); originalList.add("6789034"); originalList.add("34534356"); List<String> modifiedList = new ArrayList<String>(); int listSize = originalList.size(); for(int i=0; i< listSize; i++) { String str = ""; str+="("+originalList.get(i)+")"; if(i < listSize - 1) str+=","; modifiedList.add(str); } modifiedList.forEach(System.out::println); ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 1 What is best way to convert List into comma separated String to pass in SQL while querying database?
Medium
medium.com › @AlexanderObregon › turning-a-java-list-into-a-comma-separated-string-efc1b6c44d1b
Turning a Java List into a Comma-Separated String | Medium
June 20, 2025 - On its own, one loop won’t break anything, but in code that runs often or handles longer lists, it turns into a problem fast. StringBuilder avoids all that waste by holding one growing buffer where all the pieces go. You append to the same object each time, and then turn it into a String once at the end. Here’s the common setup when you want to avoid a trailing comma.
Sanaulla
sanaulla.info › 2013 › 05 › 07 › converting-a-list-into-comma-separated-value-string-in-java
Converting A List Into Comma Separated Value String In Java - Experiences Unlimited
When working with this concept in Java, keep these best practices in mind: Always prefer immutability where possible to reduce bugs in concurrent environments. Use the principle of least surprise — your code should behave as other developers expect. Write unit tests for every public method to catch regressions early. Leverage IDE tooling (IntelliJ IDEA, Eclipse) to catch type errors before runtime. Understanding Converting A List Into Comma Separated Value String In Java is essential for any Java developer looking to write professional-grade code.
javathinking
javathinking.com › blog › convert-list-to-string-with-comma-java
Convert List to String with Comma in Java — javathinking.com
Use StringBuilder or Stream API: For better performance, use StringBuilder or the Java 8 Stream API instead of the + operator for string concatenation. Handle null Values: Always check for null values in the list and handle them appropriately, such as filtering them out. Choose the Right Library: If you are already using Apache Commons Lang in your project, it's convenient to use the StringUtils.join method. Converting a list to a comma-separated string in Java can be achieved in multiple ways.