How to combine a List[List[String],Int] to a single List[String] in Scala?

Prishi Kumar Source

The list I am getting is by converting it to list from a map, which looks like this

Map((List(3,0,Blank,20) <- 53, (List(10,Blank,392,000) <- 53),(List(3,8,08,31) <- 1))

my list is like

List((List(3,0,Blank,20),53), (List(10,Blank,392,000),53),(List(3,8,08,31),1))

My expected output is



answered 6 days ago Patryk Rudnicki #1

Your every object contains List and Int element so you can make easily map:

val list = List((List(3,0,Blank,20),53), (List(10,Blank,392,000),53),(List(3,8,08,31),1)) => elem._1 :+ elem._2)

Output from this should be like you want

If you'll receive List[Any] you need to convert Int to String so only one change elem._2.toString

comments powered by Disqus