How to convert a List 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[]) {
        List<String> list = new ArrayList<>(Arrays.asList("java", 
                                                          "c++", 
                                                          "php", 
                                                          "python")); 
        String s = String.join(", ", list); 

        System.out.println(s); 
    }
}



/*
run:

java, c++, php, python

*/

 



answered May 22, 2020 by avibootz

Related questions

3 answers 190 views
1 answer 108 views
2 answers 167 views
1 answer 87 views
1 answer 106 views
1 answer 118 views
1 answer 126 views
...