링크모음/코틀린

코틀린에서 list 를 map 으로 빠르게 변경하기

행복한 수지아빠 2018. 1. 4. 11:56
반응형

You have two choices:

The first and most performant is to use associateBy function that takes two lambdas for generating the key and value, and inlines the creation of the map:

val map = friends.associateBy({it.facebookId}, {it.points})

The second, less performant, is to use the standard map function to create a list of Pair which can be used by toMap to generate the final map:

val map = friends.map { it.facebookId to it.points }.toMap()



캬 멋집니다~

반응형