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 128 views
2 answers 169 views
3 answers 194 views
1 answer 88 views
2 answers 140 views
2 answers 109 views
...