- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Set of String to a comma separated String in Java
Let us first create a set with string values −
Set<String>set = new HashSet<>(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six"));
Now, convert it to a comma separated string using String.join() −
String str = String.join(", ", set);
Example
Following is the program to convert set of string to a comma separated string in Java −
import java.util.*; public class Demo { public static void main(String args[]) { Set<String>set = new HashSet<>(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six")); System.out.println("Set = " + set); String str = String.join(", ", set); System.out.println("Comma separated String: "+ str); } }
Output
Set = [Five, Six, One, Four, Two, Three] Comma separated String: Five, Six, One, Four, Two, Three
- Related Articles
- Convert a List of String to a comma separated String in Java
- Java Program to Convert a List of String to Comma Separated String
- Swift Program to Convert an Set of String to Comma Separated String
- Convert String into comma separated List in Java
- How to convert a comma separated String into an ArrayList in Java?
- Python program to convert list of string to comma separated string
- How to create a comma separated string from a list of string in C#?
- How to sum a comma separated string (string with numbers) in MySQL?
- Convert Set of String to Array of String in Java
- Remove specific word in a comma separated string with MySQL
- How to use a comma-separated string in an `IN ()` in MySQL?
- MySQL query to get a single value from position of comma-separated string?
- Regex to find string and next character in a comma separated list - MySQL?
- How to convert comma seperated java string to an array.
- Converting a comma separated string to separate arrays within an object JavaScript

Advertisements