Skip to content

Instantly share code, notes, and snippets.

@thiagoolsilva
Last active June 13, 2018 12:14
Show Gist options
  • Save thiagoolsilva/1a99ff08c3ffbf6337bcc2940742cfd6 to your computer and use it in GitHub Desktop.
Save thiagoolsilva/1a99ff08c3ffbf6337bcc2940742cfd6 to your computer and use it in GitHub Desktop.
fun joinStrings(collection: Collection<String>) = joinStrings(collection = collection, separator = ",")
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