Skip to content

Instantly share code, notes, and snippets.

@sa7mon
Created September 17, 2014 22:23
Show Gist options
  • Save sa7mon/9c99fd8ddf6287b74155 to your computer and use it in GitHub Desktop.
Save sa7mon/9c99fd8ddf6287b74155 to your computer and use it in GitHub Desktop.
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,
commaSeparatedValues.lastIndexOf(","));
}
return commaSeparatedValues;
} // End of convertListToCsv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment