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.
- Get the List of String.
- Form a comma separated String from the List of String using join() method by passing comma ‘, ‘ and the list as parameters.
- Print the String.
Below is the implementation of the above approach:
Program:
// 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); } } |
chevron_right
filter_none
Recommended Posts:
- Convert String into comma separated List in Java
- Convert a Set of String to a comma separated String in Java
- Program to convert List of Integer to List of String in Java
- Program to convert List of String to List of Integer in Java
- Convert List of Characters to String in Java
- Convert a String to a List of Characters in Java
- Convert an ArrayList of String to a String array in Java
- Convert Set of String to Array of String in Java
- Print all possible ways to convert one string into another string | Edit-Distance
- Convert String to Date in Java
- Convert String to Double in Java
- Program to convert set of String to set of Integer in Java
- Program to convert String to IntStream in Java
- Program to convert IntStream to String in Java
- Program to Convert Set of Integer to Set of String in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



