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 435 views
1 answer 247 views
2 answers 372 views
1 answer 227 views
1 answer 259 views
1 answer 241 views
1 answer 281 views
...