how can I turn two arrays into a map whose keys ar...
# getting-started
o
how can I turn two arrays into a map whose keys are from one array and values are from the other?
m
So the first element from the first array are the key for the first element of the second array?
o
it seems it’s done like this
val map = friends.associateBy({it.facebookId}, {it.points})
but this works on a list
what I have is an object with 2 lists
and yes @marstran like you said first
m
Please give an example input and the expected output.
Ok, in that case you could do
list1.zip(list2).toMap()
.
But beware, it will drop elements if the lists have different lengths.
o
no they are symmetrical
in fact the result from the API should’ve been pairs
not 2 lists, lol