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
Answer from BobTheBuilder on Stack OverflowBaeldung
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 - String commaSeparatedUsingReduce = arraysAsList.stream() .reduce((x, y) -> x + "," + y) .get(); assertThat(commaSeparatedUsingReduce).isEqualTo("ONE,TWO,THREE"); Alternatively, we can also use the utility classes provided by the Apache Commons ...
DZone
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
June 29, 2016 - package net.reversecoding.examples; import static java.util.stream.Collectors.joining; import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; import org.junit.Test; public class CsvUtil { private static final String SEPARATOR = ","; public static String toCsv(List < String > listToConvert) { return String.join(SEPARATOR, listToConvert); } @Test public void toCsv_csvFromListOfString() { List < String > cities = Arrays.asList( "Milan", "London", "New York", "San Francisco"); String expected = "Milan,London,New York,San Francisco"; assertEquals(expected, toCs
Top answer 1 of 3
507
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
Reverse Coding
reversecoding.net › java-8-convert-list-string-comma
Java 8 - Convert List to String comma separated | Reverse Coding
May 22, 2016 - package net.reversecoding.examples; import static java.util.stream.Collectors.joining; import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; import org.junit.Test; public class CsvUtil { private static final String SEPARATOR = ","; public static String toCsv(List<String> listToConvert){ return String.join(SEPARATOR, listToConvert); } @Test public void toCsv_csvFromListOfString(){ List<String> cities = Arrays.asList( "Milan", "London", "New York", "San Francisco"); String expected = "Milan,London,New York,San Francisco"; assertEquals(expected, toCsv(cities
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 - In the following example, we will create a list of strings and then convert it to a comma-separated string using a for loop and StringBuilder: import java.util.ArrayList; import java.util.List; public class ListToCommaSeparatedString { public ...
Top answer 1 of 9
62
Using Java 8 you could do it in one line:
String addressID = addresses
.stream()
.map(a -> String.valueOf(a.addressId))
.collect(Collectors.joining(","));
2 of 9
16
for converting to comma seperated String use something like this:
String commaSeparatedStr = addresses
.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
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 ... "Three", "Four")); System.out.println("List = " + myList); // comma separated String str = String.join(", ", myList); System.out.println("String (Comma Separated) = " + str); } }...
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 - Converting a List to String with Examples - Java Code Geeks
July 5, 2021 - First, we will understand how to make List to String using toString() method. Next, Collection to String with comma separator or custom delimiter using Java 8 Streams Collectors api and String.join() method.
Medium
medium.com › 360learntocode › how-to-create-a-list-of-string-to-comma-separated-string-055dc0ec9ed4
How to Create a List of String to Comma Separated String | by kumar chapagain | 360learntocode | Medium
March 10, 2025 - import java.util.Arrays; import java.util.List; import java.util.StringJoiner; public class JavaStringJoin { public static void main(String[] args) { List <String> stringList = Arrays.asList("apple","banana","grapes"); StringJoiner stringJoiner = new StringJoiner(","); for (String element : stringList){ stringJoiner.add(element); } System.out.println(stringJoiner.toString()); } }
Kokaruk
kokaruk.com › 2017 › 09 › 15 › quickly-convert-list-of-ints-to-string-using-streams
Convert List <Integer> to comma separated string · class Rock implements Throwable
April 11, 2023 - 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
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.
GeeksforGeeks
geeksforgeeks.org › java › convert-string-into-comma-separated-list-in-java
Convert String into comma separated List in Java - GeeksforGeeks
December 11, 2018 - // Java program to convert String ... String array to List of String // This List is modifiable List<String> list = new ArrayList<String>( Arrays.asList(elements)); // Print the comma separated List System.out.println("Comma separated ...
GeeksforGeeks
geeksforgeeks.org › java › convert-arraylist-to-comma-separated-string-in-java
Convert ArrayList to Comma Separated String in Java - GeeksforGeeks
July 23, 2025 - // Java program to Convert ArrayList to // Comma Separated String // Using Apache Commons StringUtils class // Importing required classes import java.util.ArrayList; import org.apache.commons.collections4.CollectionUtils; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating an empty ArrayList of string type ArrayList<String> geekcourses = new ArrayList<String>(); // Adding elements to ArrayList // using add() method geekcourses.add("Data Structures"); geekcourses.add("Algorithms"); geekcourses.add("Operating System"); geekcourses.add("Comp