BeginnerCollections

Map Example

Store key-value pairs in a map.

kotlin
fun main() {
    val user = mapOf(
        "name" to "Juned",
        "skill" to "Kotlin"
    )
    println(user["name"])
    println(user["skill"])
}
Output
Juned Kotlin

Explanation

mapOf creates a read-only map. Access values by key using [].

Related Tutorials