Thursday, July 9, 2026
HomeLanguagesJavaConvert a List of String to a comma separated String in Java

Convert a List of String to a comma separated String in Java

Given a List of String, the task is to convert the List to a comma separated String in Java. 

Examples:

Input: List<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"]
Output: "Geeks, For, Geeks"

Input: List<String> = ["G", "e", "e", "k", "s"]
Output: "G, e, e, k, s"

Approach: This can be achieved with the help of join() method of String as follows.

  1. Get the List of String.
  2. Form a comma separated String from the List of String using join() method by passing comma ‘, ‘ and the list as parameters.
  3. Print the String.

Below is the implementation of the above approach: 

Program: 

Java




// Java program to convert List of String
// to comma separated String
 
import java.util.*;
 
public class GFG {
    public static void main(String args[])
    {
 
        // Get the List of String
        List<String>
            list = new ArrayList<>(
                Arrays
                    .asList("Geeks",
                            "ForGeeks",
                            "GeeksForGeeks"));
 
        // Print the List of String
        System.out.println("List of String: " + list);
 
        // Convert the List of String to String
        String string = String.join(",", list);
 
        // Print the comma separated String
        System.out.println("Comma separated String: "
                           + string);
    }
}


Output

List of String: [Geeks, ForGeeks, GeeksForGeeks]
Comma separated String: Geeks,ForGeeks,GeeksForGeeks
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6901 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12111 POSTS0 COMMENTS
Shaida Kate Naidoo
7020 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS