Kotlin HashMap entries.filter过滤forEach

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

kotlin协程flow filter map flowOn zip combine(1)_zhangphil的博客-CSDN博客一、flow ,emit,onCompletion,collect。四、map,重组改写数据。八、conflate 合并。九、debounce去重。二、函数作为flow。https://blog.csdn.net/zhangphil/article/details/130084723

相关推荐
MengFly_4 小时前
KotlinInline关键字
kotlin
用户69371750013846 小时前
27.Kotlin 空安全:安全转换 (as?) 与非空断言 (!!)
android·后端·kotlin
用户985120035836 小时前
KotlinInline关键字
kotlin
Kapaseker8 小时前
如果我问你 Context,你扛得住吗?
android·kotlin
RainyJiang17 小时前
聊聊协程里的 Semaphore:别让协程挤爆门口
android·kotlin
spencer_tseng1 天前
eclipse 4.7 kotlin android
android·kotlin
Kapaseker1 天前
十分钟速览 Kotlin Flow 操作符
android·kotlin
用户69371750013841 天前
25.Kotlin 空安全:Kotlin 的灵魂:可空性 (?) 与空安全
android·后端·kotlin
用户69371750013841 天前
26.Kotlin 空安全:安全调用:安全调用运算符 (?.) 与 Elvis 运算符 (?:)
android·后端·kotlin
モンキー・D・小菜鸡儿2 天前
Android14 新特性与适配指南
android·kotlin·安卓新特性