Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何通过Scala中的另一个字符串“加入”一个可迭代的字符串?
val thestrings = Array("a","b","c") val joined = ??? println(joined)
我希望此代码输出a,b,c(通过“,”连接元素)。
a,b,c
mkString怎么样?
theStrings.mkString(",")
存在一个变体,您也可以在其中指定前缀和后缀。
有关使用foldLeft的实现,请参见此处,该实现更为冗长,但出于教育的目的,也许值得一看。