Scala - convert List of Lists into a single List: List[List[A]] to List[A]
问题 What's the best way to convert a List of Lists in scala (2.9)? I have a list: List[List[A]] which I want to convert into List[A] How can that be achieved recursively? Or is there any other better way? 回答1: List has the flatten method. Why not use it? List(List(1,2), List(3,4)).flatten > List(1,2,3,4) 回答2: Given the above example, I'm not sure you need recursion. Looks like you want List.flatten instead. e.g. scala> List(1,2,3) res0: List[Int] = List(1, 2, 3) scala> List(4,5,6) res1: List[Int]