Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert List(String,String) to ListMap[String,String]?

I have a list of type List(String,String) and I wanted to convert it to map. When I used toMap method I found that it does not preservers the order of data that is there in the List. However my goal is to convert the list to Map by keeping the order of the data same as of List. I learned that ListMap preserves the insertion order(but it is immutable) so I can use the LinkedHashMap with map function to insert the data sequentially into LinkedHashMap but that means I need to iterate over all the elements which is pain. Can anyone please suggest me a better approach? Thanks

like image 492
Explorer Avatar asked Jan 18 '17 14:01

Explorer


Video Answer


1 Answers

This should do it :

val listMap = ListMap(list : _*)
like image 94
C4stor Avatar answered Oct 05 '22 23:10

C4stor