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

相关推荐
JohnnyDeng9420 小时前
【Android】ViewModelScope 与协程生命周期管理:告别内存泄漏,掌控异步边界
android·kotlin·mvvm·协程
alexhilton1 天前
Android的Agent优先时代:构建时vs运行时
android·kotlin·android jetpack
JohnnyDeng942 天前
【Android】Android 包体积优化:R8/ProGuard 深度配置全攻略
android·性能优化·kotlin·jetpack
逐光老顽童2 天前
用 Jetpack Compose + MVI 开发了一个 Authenticator 双因素认证应用
架构·kotlin
JohnnyDeng942 天前
【Android】Hilt 依赖注入:原理与最佳实践
android·kotlin·mvvm·hilt
杉氧3 天前
Kotlin 协程深度解析④:架构实战——在 MVVM/MVI 中的进阶应用
android·kotlin
杉氧3 天前
Kotlin 协程深度解析③:流式编程——Flow 的响应式进化
android·kotlin
Coffeeee3 天前
Android16升级,预测性返回适配起来到底难不难
android·程序员·kotlin
QING6183 天前
Kotlin 协程新手指南 —— 结构化并发
android·kotlin·android jetpack
Kapaseker3 天前
为什么 Java 要废弃 Thread.stop()?看完这篇你就懂了
android·kotlin