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

相关推荐
Fate_I_C2 小时前
ViewModel 的生命周期与数据保持
android·kotlin
Fate_I_C3 小时前
Kotlin函数一
android·开发语言·kotlin
pengyu3 小时前
【Kotlin 协程修仙录 · 炼气境 · 初阶】 | 感受天地灵气,写出第一个挂起函数
android·kotlin
molong9317 小时前
SIM 卡监听(电话监听)
android·学习·kotlin
Kapaseker8 小时前
你的进度条与众不同 — Compose 条纹
android·kotlin
android_cai_niao8 小时前
Kotlin 集合常用操作
kotlin·集合·集合操作
JMchen1238 小时前
第 1 篇|Kotlin 基础入门 —— 变量、函数与空安全
开发语言·kotlin·android 入门·kotlin 空安全·android 零基础
常利兵1 天前
Kotlin类型魔法:Any、Unit、Nothing 深度探秘
android·开发语言·kotlin
tmacfrank1 天前
Kotlin 协程十一 —— 协作、互斥锁与共享变量
java·开发语言·kotlin