You can do it in two steps with StringUtils only,

List<String> s = new ArrayList<>();
s.add("one");
s.add("two");
s.add("three");

String step1 = StringUtils.join(s, "\", \"");// Join with ", "
String step2 = StringUtils.wrap(step1, "\"");// Wrap step1 with "

System.out.println(step2);

Output,

"one", "two", "three"

BUT

I need to pass them in a mongo DB query when using $in operator

For mongodb query you don't need to build it this way, specifically in case of $in you can query documents in following way,

BasicDBObject yourInQuery = new BasicDBObject();
yourInQuery.put("in_column", new BasicDBObject("$in", yourList));
DBCursor cursor = collection.find(yourInQuery);

Please read more about this in following link,

  • Find or Query Data with Java Driver
Answer from Akash Thakare on Stack Overflow
Discussions

Best way to convert list to comma separated string in java - Stack Overflow
I have Set result & would like to convert it to comma separated string. My approach would be as shown below, but looking for other opinion as well. List slist = new More on stackoverflow.com
🌐 stackoverflow.com
How to convert comma separated and double quoted words string to list/array of strings in Java - Stack Overflow
I have the below input string: "["role_A","role_B","role_C"]" I want to convert it to a list/array of strings containing all values(role_A, role_B, role_C).... More on stackoverflow.com
🌐 stackoverflow.com
java - How to convert a List<String> into a comma separated string without iterating List explicitly - Stack Overflow
I am having ArrayList of String, which I need to convert to comma separated list, without space. The ArrayList toString() method adds square brackets, comma and space. More on stackoverflow.com
🌐 stackoverflow.com
java - How to convert List<Object> into comma separated String - Stack Overflow
I am getting list of Address objects from the DB call. ArrayList addresses = new ArrayList (); Each Address has an int addressId property. I am writing an update query wher... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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); } }
🌐
Bitcompiler
tutorials.bitcompiler.com › 2024 › 03 › how-to-convert-list-of-strings-to-comma.html
How to convert a List of Strings to a Comma Separated String with Single Quotes In Java
This Java code uses Java Streams to map each element of the list to a string with single quotes around it using the map operation. Then, it collects these strings into a single comma-separated string using the Collectors.joining method.
🌐
Medium
medium.com › @as.vignesh › append-quotes-to-strings-in-an-array-and-make-it-comma-separated-string-in-java-5dbb9edccaa8
Append quotes to strings in an array and make it comma ...
Open in app · Sign up · Sign in · Write · PAGE NOT FOUND · Out of nothing, something · You can find (just about) anything on Medium — apparently even a page that doesn’t exist. Maybe these stories will take you somewhere new · A fascinating variety of Irish facts, brought to you ...
🌐
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 - Learn how to turn a Java List into a comma-separated string using loops, StringBuilder, and String.join, with a close look at how each method works internally.
Find elsewhere
🌐
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 - 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 ...
🌐
Medium
medium.com › @alxkm › converting-a-list-of-strings-to-a-comma-separated-string-in-java-multiple-approaches-ebb86745c889
Java Interview: Converting a List of Strings to a Comma-Separated String in Java: Multiple Approaches | by Alex Klimenko | Medium
August 9, 2025 - StringBuilder sb = new StringBuilder(); for (int i = 0; i < names.size(); i++) { sb.append(names.get(i)); if (i < names.size() - 1) { sb.append(","); } } String result = sb.toString(); System.out.println(result); // Output: Alice,Bob,Charlie · Works in all Java versions.
🌐
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 Java 8 and later, we can use the method Collectors.joining() from the Streams API to convert a list of strings to a comma-separated string.
🌐
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 - 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
🌐
Attacomsian
attacomsian.com › blog › java-convert-list-to-comma-separated-string
Convert a list to a comma-separated string in Java
October 29, 2022 - You can use core Java functions, Steams API, and Apache Commons Lang to convert a list into a string. The most common way to convert a list of strings into a comma-separated string is by using the static join() method from the String class:
🌐
Sabe
sabe.io › blog › java-convert-list-comma-separated-string
How to Convert a List to Comma-Separated String in Java | Sabe
May 25, 2022 - The most straight-forward way to convert a string list to a comma-separated string is to use the join() method that exists on the String class. Simply call the join() method on the list and pass in the separator you want to use.
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-arraylist-to-comma-separated-string-in-java
Convert ArrayList to Comma Separated String in Java - GeeksforGeeks
July 23, 2025 - We can convert ArrayList to a comma-separated String using StringJoiner which is a class in java.util package which is used to construct a sequence of characters(strings) separated by a delimiter and optionally starting with a supplied prefix ...
🌐
Coderanch
coderanch.com › t › 433460 › java › Convert-List-comma-delimited-string
Convert List to comma delimited string (Beginning Java forum at Coderanch)
The only way I see to do it is either with the Iterator above, or with a foreach and getting rid of the comma at the end of the string after you exit the loop. Is there a similar way to do this in a foreach loop?