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 天前
Kotlin学习第 8 课:Kotlin 进阶特性:简化代码与提升效率
android·java·kotlin
Kapaseker1 天前
每个Kotlin开发者应该掌握的最佳实践,第一趴
kotlin
丑小鸭是白天鹅2 天前
Kotlin协程详细笔记之切线程和挂起函数
开发语言·笔记·kotlin
程序员江同学2 天前
ovCompose + AI 开发跨三端的 Now in Kotlin App
android·kotlin·harmonyos
charlie1145141912 天前
Kotlin 的 apply / with / run 详解
开发语言·kotlin·程序设计·面对对象
柿蒂2 天前
从if-else和switch,聊聊“八股“的作用
android·java·kotlin
叽哥2 天前
Kotlin学习第 7 课:Kotlin 空安全:解决空指针问题的核心机制
android·java·kotlin
小孔龙3 天前
02.Kotlin Serialization 属性序列化控制
kotlin·json
tangweiguo030519874 天前
Kable使用指南:Android BLE开发的现代化解决方案
android·kotlin
yzpyzp4 天前
kotlin的函数前面增加suspend关键字的作用
android·开发语言·kotlin