我的 list 如下
我想把它转换成下面的列表 map
i.e. for a, we have a list of 1 and 4, since the key is the same.
答案是
I tried associateBy
in Kotlin
data class Combine(val alpha: String, val num: Int)
val list = arrayListOf(Combine("a", 1), Combine("b", 2), Combine("c", 3), Combine("a", 4))
val mapOfList = list.associateBy ( {it.alpha}, {it.num} )
println(mapOfList)
但似乎不管用.我怎么能在Kotlin 这么做呢?