mapValues
Returns a new map with entries having the keys of this map and the values obtained by applying the transform function to each entry in this Map.
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("beverage" to 2.7, "meal" to 12.4)
val map2 = map1.mapValues { it.value.toString() + "$" }
println(map2) // {beverage=2.7$, meal=12.4$}
//sampleEnd
}
Returns a new map with entries having the keys of this map and the values obtained by applying the transform function to each entry in this Map.
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("beverage" to 2.7, "meal" to 12.4)
val map2 = map1.mapValues { it.value.toString() + "$" }
println(map2) // {beverage=2.7$, meal=12.4$}
//sampleEnd
}