Skip to content

Instantly share code, notes, and snippets.

@thiagoolsilva
Created June 11, 2018 22:44
Show Gist options
  • Save thiagoolsilva/3eec2156a2e73866d143ee2e12ed865f to your computer and use it in GitHub Desktop.
Save thiagoolsilva/3eec2156a2e73866d143ee2e12ed865f to your computer and use it in GitHub Desktop.
fun joinStrings(
collection: Collection<String>,
separator: String = ","
): String {
val result = StringBuffer()
val firstElement = 0
for((index, word) in collection.withIndex()) {
if(index != firstElement) result.append(separator)
result.append(word)
}
return result.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment