In Kotlin, you can get the number of key-value pairs in a Map using its size property:
val scores = mutableMapOf<String, Int>()
scores["Alice"] = 95
scores["Bob"] = 87
scores["Charlie"] = 72
val count = scores.size
println(count) // 3
size is the number of entries. You can also check if it's empty with isEmpty():
println(scores.isEmpty()) // false
val empty = mutableMapOf<String, Int>()
println(empty.size) // 0
Assignment
Follow the Coding Tutorial and get the number of entries in scores!
Hint
Use scores.size and assign it to count.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
