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

相关推荐
移动开发者1号6 小时前
Android 同步屏障(SyncBarrier)深度解析与应用实战
android·kotlin
移动开发者1号6 小时前
深入协程调试:协程调试工具与实战
android·kotlin
fundroid1 天前
Kotlin 协程:Channel 与 Flow 深度对比及 Channel 使用指南
android·kotlin·协程
移动开发者1号1 天前
深入理解原子类与CAS无锁编程:原理、实战与优化
android·kotlin
移动开发者1号1 天前
深入理解 ThreadLocal:原理、实战与优化指南
android·kotlin
Devil枫1 天前
Kotlin高级特性深度解析
android·开发语言·kotlin
ChinaDragonDreamer1 天前
Kotlin:2.1.20 的新特性
android·开发语言·kotlin
每次的天空2 天前
Android-自定义View的实战学习总结
android·学习·kotlin·音视频
移动开发者1号2 天前
使用 Android App Bundle 极致压缩应用体积
android·kotlin
移动开发者1号2 天前
构建高可用线上性能监控体系:从原理到实战
android·kotlin