嗨,我是斯卡拉的新手, 我想打开
List(List("hello=10","hi=21","there=13","bro=44","family=44","technology=35","hi=20","hello=100","hi=21","there=13","bro=44","family=44","technology=35","hi=21","there=13","bro=44","family=44","family=44"))
变成类似
List("hello=10","hi=21","there=13","bro=44","family=44","technology=35","hi=20","hello=100","hi=21","there=13","bro=44","family=44","technology=35","hi=21","there=13","bro=44","family=44","family=44")
我们如何达到目标?
谢谢!
答案 0 :(得分:1)
您可以使用列表的内置方法展平。
scala> val list = List(List("hello=10","hi=21","there=13","bro=44","family=44","technology=35","hi=20","hello=100","hi=21","there=13","bro=44","family=44","technology=35","hi=21","there=13","bro=44","family=44","family=44"))
list: List[List[String]] = List(List(hello=10, hi=21, there=13, bro=44, family=44, technology=35, hi=20, hello=100, hi=21, there=13, bro=44, family=44, technology=35, hi=21, there=13, bro=44, family=44, family=44))
scala> list.flatten
res0: List[String] = List(hello=10, hi=21, there=13, bro=44, family=44, technology=35, hi=20, hello=100, hi=21, there=13, bro=44, family=44, technology=35, hi=21, there=13, bro=44, family=44, family=44)