-1

I have a problem, I must to read a CSV file like:

csv structure

I want to get a list by column:

listKey1 = {value1, value11, value111, value1111}.

listKey2 = {value2, value22, value222}

....

Help me solve it!!! Please…

2

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.