I have two arraylists (open to working with other collections) and need to output a csv file that determines whether the contents of these arraylists is the same; cell by cell comparison essentially. The arraylists are taken from a result set and are sorted. They look like this:
sourceData = (9, Orlando, Feb 28, 668, Lloydtown, Dec 1, etc)
targetData = (9, Caledon, Jan 19, 38, South Hark, Dec 1, etc)
What I attempted is to take the first value of the first arraylist, the first value of the second arraylist and then compare them and print that to a CVS file.
for (int i = 0; i <sizeOfData; i++) {
if (sourceData.get(i).equals(targetData.get(i))){
validator = ("True");
} else {
validator = ("False");
}
csvFilePrinter.printRecord(sourceData.get(i), targetData.get(i), validator);
}
The output looks as desired:
9, 9, true
However, I need the next row in the CSV file to display:
668, 38, false
so that the overall pattern is:
9, 9, true, Orlando, Caledon, false, Feb 28, Jan 19, false
668, 38, false, Lloydtown, South Hark, false, Dec 1, Dec 1, true
where once I put headers, and say the second column is 'city', only city values will be displayed in column 2.
I've tried every which way to write is, but the format of the CSV file is all wrong as every time I use csvFilePrinter, it writes to the next line. How do I write to the next column? When I put what I want in one row into an array I can make this work, but my result sets are going to be different every time so I cannot hardcode how many columns I will need. How can you write across a row, not down a column when writing to a CVS file?
I don't see the solution to my problem in any of the linked posts...
results; and then for (List row: results ) {csvFilePrinter.printRecord(row);}
– John Tribe Aug 14 '17 at 18:37