Kotlin linkedMapOf filterKeys
Kotlin
fun main(args: Array<String>) {
val lhm = linkedMapOf<String, Any>(
Pair("name", "phil"), //因为key相同都为 name,被后面的覆盖。
Pair("year", 2024),
Pair("name", "fly"),
Pair("FLOAT", 20.24f)
)
println(lhm)
val map = lhm.filterKeys {
it == "name"
}
println("keys=${map.keys}")
println("values=${map.values}")
println("entries=${map.entries}")
}
{name=fly, year=2024, FLOAT=20.24}
keys=[name]
values=[fly]
entries=[name=fly]