java create csv file from list

Solutions on MaxInterview for java create csv file from list by the best coders in the world

showing results for - "java create csv file from list"
Andrea
21 Jul 2016
1
2        String input = "[\"user1\",\"track1\",\"player1\", \"user1\",\"track2\",\"player2\", \"user1\",\"track3\",\"player3\"]";
3        input = input.substring(1, input.length() - 1); // get rid of brackets
4        String[] split = input.split(" ");
5
6        FileWriter writer = new FileWriter("/Users/user/tmp/csv/sto1.csv");
7
8        for(String s : split) {
9            String[] split2 = s.split(",");
10            writer.write(Arrays.asList(split2).stream().collect(Collectors.joining(",")));
11            writer.write("\n"); // newline
12        }
13
14        writer.close();