Scala-将列表列表转换为单个列表:List [List [A]]到List [A] [英] Scala - convert List of Lists into a single List: List[List[A]] to List[A]
本文介绍了Scala-将列表列表转换为单个列表:List [List [A]]到List [A]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在scala(2.9)中转换列表列表的最佳方法是什么?
What's the best way to convert a List of Lists in scala (2.9)?
我有一个列表:
List[List[A]]
我想转换成
List[A]
该如何递归实现?还是还有其他更好的方法?
How can that be achieved recursively? Or is there any other better way?
推荐答案
列表具有flatten方法.为什么不使用它?
List has the flatten method. Why not use it?
List(List(1,2), List(3,4)).flatten
> List(1,2,3,4)
这篇关于Scala-将列表列表转换为单个列表:List [List [A]]到List [A]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文