Answers for "kotlin map example list"

1

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])  
    }  
}
Posted by: Guest on November-10-2021
1

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 }))
}
Posted by: Guest on September-25-2020

Browse Popular Code Answers by Language