https://kotlinlang.org logo
#android
Title
# android
v

viralshah

04/18/2020, 2:36 AM
Whats the best way to manipulate a Kotlin map to get this result
Copy code
val k = "total"


[{"id": "123", "total": "56.00"}, {"id": "456", "total": "55.00"}]

to

map id -> k 

{"123": "56.00", "456": "55.00"}
j

jw

04/18/2020, 2:58 AM
listOfMaps.map { it["id"] to it[k] }.toMap()
d

Dominaezzz

04/18/2020, 3:36 AM
listOfMaps.associate { it["id"] to it[k] }
should also work.
v

viralshah

04/18/2020, 4:51 AM
cheers guys