how to create map in kotlin
fun main(args: Array<String>){ val myMap = mapOf<Int,String>(1 to "Ajay", 4 to "Vijay", 3 to "Prakash") for(key in myMap.keys){ println(myMap[key]) } }
make map kotlin
val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
create a map from list kotlin
fun main() { val numbers = listOf("one", "two", "three", "four") println(numbers.associateBy { it.first().toUpperCase() }) println(numbers.associateBy(keySelector = { it.first().toUpperCase() }, valueTransform = { it.length })) }
kotlin map list
val numbers = setOf(1, 2, 3) println(numbers.map { it * 3 }) // [3, 6, 9]
Source: kotlinlang.org