 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a List of String to a comma separated String in Java
At first, let’s say the following is our List of String −
List<String> myList = new ArrayList<>(Arrays.asList("One", "Two", "Three", "Four"));
Now, convert this to a comma separated string using String.join()
String str = String.join(", ", myList);
Example
Following is the program to convert 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);
   }
}
Output
List = [One, Two, Three, Four] Comma separated String: One, Two, Three, Four
Advertisements
                    