如何在scala中解压缩列表(list())
嗨,我是scala的初学者, 我想打开行李如何在scala中解压缩列表(list()),scala,nested-lists,flatten,Scala,Nested Lists,Flatten,嗨,我是scala的初学者, 我想打开行李 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","
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")
我们怎样才能取得成功
谢谢 您可以使用内置的列表展平方法
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)
使用
展平
方法