Given a Set of String, the task is to convert the Set to a comma separated String in Java.
Input: Set<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"] Output: "Geeks, For, Geeks" Input: Set<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 Set of String.
- Form a comma separated String from the Set of String using join() method by passing comma ‘, ‘ and the set as parameters.
- Print the String.
Below is the implementation of the above approach:
Set of String: [ForGeeks, Geeks, GeeksForGeeks] Comma separated String: ForGeeks, Geeks, GeeksForGeeks
- Convert a List of String to a comma separated String in Java
- Convert String into comma separated List in Java
- Convert an ArrayList of String to a String array in Java
- Convert Set of String to Array of String in Java
- How to convert a String to an Int in Java?
- Convert String to Date in Java
- How to convert an Array to String in Java?
- Convert String to Double in Java
- Print all possible ways to convert one string into another string | Edit-Distance
- Convert a String to a List of Characters in Java
- How to Convert a String value to Float value in Java with Examples
- Program to Convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Convert List of Characters to String in Java
- How to Convert a Byte value to String value in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.