I'm trying to collect CSV row as array of strings using simpleflatmapper:
try (Reader in = Files.newBufferedReader("path")) {
return org.simpleflatmapper.csv.CsvParser
// .mapTo(String[].class)
.stream(in)
// .parallel()
// .flatMap(Arrays::stream)
.map(line -> {return new ArrayList<>(Arrays.asList(line));})
// .map(Arrays::asList)
.collect(Collectors.toList());
} catch (Exception e) {
e.printStackTrace();
}
As I debug, the line is String[] but the value is entire row (one element) instead of many strings (many cells). How can I got the array of cells?
The CSV file is no special. Ex:
a\t b\t 1\t 2
x\t y\t 3\t 4
The issue as I see in this code .map(line -> {return new ArrayList<>(Arrays.asList(line));}) that the line contains one string value that is the whole line (with tab, space, ...) instead of many strings (each string is the value of each cell).
The whole result I want is List<List<String>> (List of lines). Each line is List<String> (list of cells). The current result is list of lines (rows), each line/row is the whole string.
CSVParserclasses. NoCsvParser. Since your question is about the Stream generated byCsvParser, how do you expect us to help, when we have no clue what it is?flatMapmethod, which threw us all for a loop. Also, you haven't shown us the input, so how would we know what you're expecting to see. Perhaps if you provided a Minimal, Complete, and Verifiable example, you wouldn't get down-votes.