-1

Hi I am beginner in scala, I want to unpack

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"))

into something like

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")

how we can achive?

Thanks!

Sergii Lagutin
  • 10,561
  • 1
  • 34
  • 43
Rams_v
  • 35
  • 4

1 Answers1

1

You can use built-in method flatten of list.

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)
Mahesh Chand
  • 3,158
  • 19
  • 37