简体   繁体   English

如何弄平字符串的序列并在Scala中重新构建?

[英]How to flatten a seq to a string and build it back in Scala?

How to flatten a Seq like ("a", "b", "c") to "a,b,c" in Scala? 如何在Scala中将Seq("a", "b", "c")"a,b,c"

And how to build one back from a comma separated String ? 以及如何用逗号分隔的String重新构建? Thanks. 谢谢。

For the first, try: 首先,请尝试:

val seq = Seq("a", "b", "c")
val string = seq.mkString(",")

For the second: 对于第二个:

val parsed = string.split(",")

which returns an Array , so if it must be a Seq then: 它返回一个Array ,所以如果它必须是一个Seq则:

val parsed = string.split(",").toSeq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM