Kotlin has joinToString
method just for this
list.joinToString()
You can change a separator like this
list.joinToString(separator = ":")
If you want to customize it more, these are all parameters you can use in this function
val list = listOf("one", "two", "three", "four", "five")
println(
list.joinToString(
prefix = "[",
separator = ":",
postfix = "]",
limit = 3,
truncated = "...",
transform = { it.uppercase() }
)
)
which outputs
[ONE:TWO:THREE:…]