How to convert a Set of String to a comma separated String in Java

1 Answer

0 votes
import java.util.*; 

public class MyClass {
    public static void main(String args[]) {
        Set<String>set = new HashSet<>(Arrays.asList("java", 
                                                     "c++", 
                                                     "php", 
                                                     "python")); 
        String s = String.join(", ", set); 

        System.out.println(s); 
    }
}



/*
run:

c++, python, java, php

*/

 



answered May 22, 2020 by avibootz

Related questions

1 answer 164 views
2 answers 208 views
3 answers 238 views
1 answer 133 views
2 answers 178 views
2 answers 161 views
...