Mapping header to rest of the records

Hello guys, I’m a newbie to scala and programming. I need help for the below problem

Input data file looks like this seq[seq[string]]
Seq(
Seq ( “name”, “place”, “age”), Seq (" Mike", “Paris”, “22”),
Seq ( “Tom”, “Boston”, “36”)
)

Problem is to map headers to rest of the records. Seq[Map[String, string]]

Output should look like

Seq(
Map(“name” - > “mike”, “place” - >“Paris”, “age” - > “22”)
Map(“name” - >“Tom”, “place” - > “Boston”, “age” - >“36”)
)

How can I achieve this result.!!
Thanks in advance guys, any help on this would be greatly appreciated

What have you tried so far and where are you stuck?

Looks like first you’ll need a way to separate the header “row” from the remainder. Then a combination of #map(), #zip() and #toMap() might do the trick - unless you want more safeguards against varying row lengths, etc.

1 Like