I have a problem, I must to read a CSV file like:
I want to get a list by column:
listKey1 = {value1, value11, value111, value1111}.
listKey2 = {value2, value22, value222}
....
Help me solve it!!! Please…
I have a problem, I must to read a CSV file like:
I want to get a list by column:
listKey1 = {value1, value11, value111, value1111}.
listKey2 = {value2, value22, value222}
....
Help me solve it!!! Please…
That's very easy to accomplish with univocity-parsers:
CsvParserSettings parserSettings = new CsvParserSettings();
ColumnProcessor columnProcessor = new ColumnProcessor();
parserSettings.setProcessor(columnProcessor);
CsvParser parser = new CsvParser(parserSettings);
parser.parse(new File("/path/to/your.csv), "UTF-8"); //all rows are submitted to the processor created above.
Map<String, List<String>> columnValues = columnProcessor.getColumnValuesAsMapOfNames();
Hope it helps.
Disclaimer: I'm the author of this library. It's open source and free (apache 2.0 license)