Skip to content

Instantly share code, notes, and snippets.

@sa7mon
sa7mon / convertListToCsv
Created September 17, 2014 22:23
Convert list to CSV
public static String convertListToCsv(List<String> listToConvert) {
String commaSeparatedValues = "";
//Iterate through the list and append comma after each values
Iterator<String> iter = listToConvert.iterator();
while (iter.hasNext()) {
commaSeparatedValues += iter.next() + ",";
}
//Remove the last comma
if (commaSeparatedValues.endsWith(",")) {
commaSeparatedValues = commaSeparatedValues.substring(0,