Kotlin Maps: How to iterate over a Map in Kotlin with a 'for' loop
Kotlin FAQ: How do I iterate over the elements in a Map
in Kotlin?
Solution
Here’s an example that shows how to iterate over the elements in a Kotlin Map
using a for
loop:
val map = mapOf("a" to 1, "b" to 2, "c" to 3) for ((k,v) in map) { println("value of $k is $v") }