associateWith 您所在的位置:网站首页 associatewith用法 associateWith

associateWith

#associateWith| 来源: 网络整理| 查看: 265

Returns a Map where keys are elements from the given collection and values are produced by the valueSelector function applied to each element.

If any two elements are equal, the last one gets added to the map.

The returned map preserves the entry iteration order of the original collection.

import kotlin.test.* fun main(args: Array) { //sampleStart val words = listOf("a", "abc", "ab", "def", "abcd") val withLength = words.associateWith { it.length } println(withLength.keys) // [a, abc, ab, def, abcd] println(withLength.values) // [1, 3, 2, 3, 4] //sampleEnd }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有