Scala: join an iterable of strings

前端 未结 1 683
春和景丽
春和景丽 2020-12-23 12:39

How do I \"join\" an iterable of strings by another string in Scala?

val thestrings = Array(\"a\",\"b\",\"c\")
val joined = ???
println(joined)
相关标签:
1条回答
  • 2020-12-23 13:20

    How about mkString ?

    theStrings.mkString(",")
    

    A variant exists in which you can specify a prefix and suffix too.

    See here for an implementation using foldLeft, which is much more verbose, but perhaps worth looking at for education's sake.

    0 讨论(0)
提交回复
热议问题