size

expect abstract val size: Int(source)

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.0

Samples

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
}
actual abstract val size: Int(source)

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.1

Samples

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
}
actual abstract val size: Int(source)

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.0

Samples

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
}
actual abstract val size: Int(source)

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.3

Samples

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
}
actual abstract val size: Int(source)

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.8

Samples

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
}
actual abstract val size: Int(source)

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.8

Samples

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
}