Best way to convert numeric array to CSV string?

csv, java, java-8

Solution

This can be done with the Streams API in a one-liner:

Arrays.stream(new int[] {0, 1, 2}).mapToObj(String::valueOf).collect(joining(","));

(assuming `import static java.util.stream.Collectors.joining`)

Problem

If I have a `String[]` (assume no commas) I can produce a CSV row simply. E.g., ``` String[] header = {"header0", "header1", "header2"}; String joined = String.join(",", header); ``` What's the nice way to do the equivalent with say `int[] vals01 = {0, 1, 2};`? (I consider using `Arrays.toString` and slicing off the ends to be ugly.)

Original source