Search⌘ K
AI Features

Map Operations

Explore Kotlin map operations within collections by learning to check keys, retrieve map size, iterate over entries with destructuring, and work with mutable maps to add or remove entries effectively.

Checking if a map contains a key

We can check if our map contains a key using the in keyword or the containsKey method.

Kotlin 1.5
fun main() {
val map = mapOf('A' to "Alex", 'B' to "Bob")
println('A' in map) // true
println(map.containsKey('A')) // true
println('Z' in map) // false
println(map.containsKey('Z')) // false
}

Checking map size

...