Originally published on 2017-09-14

Java List interface doesn’t have a method to join all members to coma separated string.

Previous versions required iterating over the list and appending and instance of Stringbuilder.

Using Java 8 Streams makes it more neat.

https://gist.github.com/rmit-s3668804-Dzmitry-Kakaruk/7cb0f29c147cfb99e503f504ba3787f5

// list of integer to string
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
String commaSeparatedNumbers = numbers.stream()
.map(i -> i.toString())
.collect(Collectors.joining(", "));
view raw CSVUtils.java hosted with ❤ by GitHub