When reading a CSV file, I want to remember/store data across multiple rows of that particular file, e.g. to make an object based on columns from line 1+2, line 3+4, etc.
While I've found a solution, I do believe there should a 'cleaner' solution for this. This is what I came up with:
public static void main(String[] args) {
try (var reader = new FileReader("src/main/java/com/kdh/snippets/loops/dummy.csv")) {
List<String[]> rows = CsvReader.read(reader);
var index1 = 0;
var index2 = 1;
// 50 lines in file = 25 iterations
for (int i = 0; i < rows.size() / 2; i++) {
String[] consumption = rows.get(index1);
String[] injection = rows.get(index2);
System.out.println("Consumption: " + consumption[8] + ", Injection: " + injection[8]);
index1 += 2;
index2 += 2;
}
} catch (IOException ex) {
System.out.println(ex);
}
}