Search code examples
kotlinkotlin-extension

How to iterate over hashmap in Kotlin?


How to iterate over HashMap in Kotlin?

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

Solution

  • 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") }