This is my CSV, first line is header, Akt (pan), Mc1-1 and etc. is content.
I need to create a function that extracts content of SearchTerm column and adds it to a List<String>
.
I tried it with this piece of code but my next processing requires to have List<String>
and not List<String[]>
. Is there a way to do that or is there any way i can take parsed List<String[]>
and make it into List<String>
only containing all the search terms?
public List<String> listAllSearchTerms() throws FileNotFoundException {
CsvParserSettings settings = new CsvParserSettings();
settings.selectIndexes(0);
CsvParser parser = new CsvParser(settings);
List<String[]> allRows = parser.parseAll(new FileReader("D:\\Projects\\cstocs-test-dev-bitbucket\\cstocs-test-core\\src\\main\\resources\\data\\searchterm.csv"));
List<String> returnList = new ArrayList<>();
allRows.remove(0);
for (String[] strings : allRows) {
returnList.addAll(Arrays.asList(strings));
}
return returnList;
}