A Far A Far - 4 years ago 159
Scala Question

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:


which I want to convert into


How can that be achieved recursively? Or is there any other better way?

Jan Jan
Answer Source

List has the flatten method. Why not use it?

List(List(1,2), List(3,4)).flatten
> List(1,2,3,4)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download