size
Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.0Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.1Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.0Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.3Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.8Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}Returns the number of key/value pairs in the map.
If a map contains more than Int.MAX_VALUE elements, the value of this property is unspecified. For implementations allowing to have more than Int.MAX_VALUE elements, it is recommended to explicitly document behavior of this property.
Since Kotlin
1.8Samples
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
println(emptyMap<Int, Int>().size) // 0
val mutableMap = mutableMapOf(1 to "one", 2 to "two")
println(mutableMap.size) // 2
mutableMap[3] = "three"
println(mutableMap.size) // 3
//sampleEnd
}