I have a csv encoding a thesaurus of some items and, expectedly, the number of entries per row are different for different rows.
The first line contains 25 tokens/synonyms. The rest of the lines have lesser. But the String[]
that are read all have length 25. The shorter rows are padded with empty strings.
Is there any way to avoid this from happening?
My code looks like this:
CSVReader reader = new CSVReader(new FileReader("thesaurus.csv", '\t'));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
System.out.println("length of the row: "+ nextLine.length);
}
Sample lines from csv:
search examination exploration hunt inquiry inspection investigation pursuit quest research chase frisking going-over inquest pursual pursuance pursuing rummage scrutiny shakedown fishing expedition legwork perquisition wild-goose chase witch hunt
school schule
saint st. st
When I print the String[] items one-by-one, I get this:
'school', 'schule', , , , , , , , , , , , , , , , , , , , , , , ,
'saint', 'st.', 'st', , , , , , , , , , , , , , , , , , , , , , ,