mapKeys
Returns a new Map with entries having the keys obtained by applying the transform function to each entry in this Map and the values of this map.
In case if any two entries are mapped to the equal keys, the value of the latter one will overwrite the value associated with the former one.
The returned map preserves the entry iteration order of the original map.
Since Kotlin
1.1Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map1 = mapOf("beer" to 2.7, "bisquit" to 5.8)
val map2 = map1.mapKeys { it.key.length }
println(map2) // {4=2.7, 7=5.8}
val map3 = map1.mapKeys { it.key.take(1) }
println(map3) // {b=5.8}
//sampleEnd
}
Returns a new Map with entries having the keys obtained by applying the transform function to each entry in this Map and the values of this map.
In case if any two entries are mapped to the equal keys, the value of the latter one will overwrite the value associated with the former one.
The returned map preserves the entry iteration order of the original map.
Since Kotlin
1.0Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map1 = mapOf("beer" to 2.7, "bisquit" to 5.8)
val map2 = map1.mapKeys { it.key.length }
println(map2) // {4=2.7, 7=5.8}
val map3 = map1.mapKeys { it.key.take(1) }
println(map3) // {b=5.8}
//sampleEnd
}