keys

expect open override val keys: MutableSet<K>(source)

Returns a MutableSet of all keys in this map.

Since Kotlin

1.0

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val map = mutableMapOf(1 to "one", 2 to "two")
val keys = map.keys
println(keys) // [1, 2]

keys.remove(1)
println(keys) // [2]
println(map) // {2=two}

// keys.add(3) // will fail with UnsupportedOperationException 
   //sampleEnd
}
actual open override val keys: MutableSet<K>(source)

Returns a MutableSet of all keys in this map.

Since Kotlin

1.3

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val map = mutableMapOf(1 to "one", 2 to "two")
val keys = map.keys
println(keys) // [1, 2]

keys.remove(1)
println(keys) // [2]
println(map) // {2=two}

// keys.add(3) // will fail with UnsupportedOperationException 
   //sampleEnd
}
actual open override val keys: MutableSet<K>(source)

Returns a MutableSet of all keys in this map.

Since Kotlin

1.8

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val map = mutableMapOf(1 to "one", 2 to "two")
val keys = map.keys
println(keys) // [1, 2]

keys.remove(1)
println(keys) // [2]
println(map) // {2=two}

// keys.add(3) // will fail with UnsupportedOperationException 
   //sampleEnd
}
actual open override val keys: MutableSet<K>(source)

Returns a MutableSet of all keys in this map.

Since Kotlin

1.8

Samples

import kotlin.test.*
import java.util.*

fun main() { 
   //sampleStart 
   val map = mutableMapOf(1 to "one", 2 to "two")
val keys = map.keys
println(keys) // [1, 2]

keys.remove(1)
println(keys) // [2]
println(map) // {2=two}

// keys.add(3) // will fail with UnsupportedOperationException 
   //sampleEnd
}