How to convert a String List to Comma Seprated String

Stream Collectors.joining

				
					import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
//------------------------

public class YourClass {

    public static void main(String[] args) {

        List<String> list = Arrays.asList("a", "b", "c");

        String result = list.stream().collect(Collectors.joining(","));

        System.out.println(result);

    }

}

				
			

Output:

				
					a,b,c
				
			

String.join

				
					import java.util.Arrays;
import java.util.List;

public class MyClass {

    public static void main(String[] args) {

        List<String> list = Arrays.asList("a","b","c");
        String result = String.join(",", list);

        System.out.println(result);

    }

}
				
			

Output:

				
					a,b,c
				
			

Javascript For Loops

Javascript For Loops in the ECMA Standard Simple For Loop The simplest type of for loop increments a variable as its iteration method. The variable

Read More »

Most Used Java Stream Map Functions

Retriving a List of attribute (field) values from a Object List (Array List) List users=new ArrayList<>(); List userIds=users .stream() .map(u->u.getId()) .collect(Collectors.toList()); Filter Objects by Attribute

Read More »
How to convert a String List to Comma Seprated String
Scroll to top