Well where you loop through the columns just add a comma.
for(String column : row) {
System.out.println(column + ", ");
}
You might need to modify it as this code adds a comma at the end of each element, including the last one. You would need to find out if column is the last element of row, and only add a comma if it ISN'T.
You could connect it to a FileWriter
(through BufferedWriter
) and output it to a .csv file if you wanted. Put this code at the beginning of your method
try {
PrintWriter pw = new PrintWriter(BufferedWriter(new FileWriter("data.csv")));
}
catch(Exception e) {
e.printStackTrace();
}
and then to print each line your loop would look like this
for (List<String> row : results.getRows()) {
for (String column : row) {
pw.print(row + ",");
}
pw.println();
}
again you would need to find out if column is the last element of row.