Kotlin HashMap entries.filter过滤forEach
Kotlin
fun main(args: Array<String>) {
val hashMap = HashMap<String, Int>()
hashMap["a"] = 1
hashMap["b"] = 2
hashMap["c"] = 3
println(hashMap)
hashMap.entries.filter {
println("filter ${it.key}-${it.value}")
it.key == "b" //此处为过滤条件,满足过滤条件为真,才会进入forEach
}.forEach {
println("forEach ${it.key}--${it.value}")
}
}
{a=1, b=2, c=3}
filter a-1
filter b-2
filter c-3
forEach b--2