Created
June 11, 2018 22:44
-
-
Save thiagoolsilva/3eec2156a2e73866d143ee2e12ed865f to your computer and use it in GitHub Desktop.
This file contains 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
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