How to iterate over HashMap in Kotlin
?
typealias HashMap<K, V> = HashMap<K, V> (source)
Alexander Romanov
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") }
Ken Zira
For the above answer, be careful with Android
below N
!
map.forEach { key, value -> println("$key = $value") }
reference to Java 8
api which leads to:
Rejecting re-init on previously-failed class java.lang.Class<T>
map.forEach { (key, value) -> println("$key = $value") }
is Kotlin
feature
来源:https://stackoverflow.com/questions/47204146/how-to-iterate-over-hashmap-in-kotlin