Recent Posts
Recent Comments
반응형
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

오늘도 공부

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

링크모음/코틀린

코틀린에서 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()



캬 멋집니다~

반응형