How to iterate over hashmap in Kotlin?

Nomi picture Nomi · Nov 9, 2017 · Viewed 68.6k times · Source

How to iterate over HashMap in Kotlin?

typealias HashMap<K, V> = HashMap<K, V> (source)

Answer

Alexander Romanov picture Alexander Romanov · Nov 9, 2017

It's not that difficult:

for ((key, value) in map) {
    println("$key = $value")
}

OR
(Updated in accordance with @RuckusT-Boom's and @KenZira's information.)

 map.forEach { (key, value) -> println("$key = $value") }