Created
September 17, 2014 22:23
-
-
Save sa7mon/9c99fd8ddf6287b74155 to your computer and use it in GitHub Desktop.
Convert list to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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