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

相关推荐
码农哈丁6 小时前
从 JVM 到 Cargo:把整个 Kotlin 项目移植到 Rust 的踩坑实录
jvm·rust·kotlin
Kapaseker9 小时前
写过 4000 行 ViewModel 后,我开始这样拆 Compose 页面
android·kotlin
新时代牛马1 天前
cyclictest 毛刺从哪来?从ftrace、latencytop、perf到IRQ/调度延迟定位
android·开发语言·python·kotlin
光电的一只菜鸡1 天前
为什么调整LSC会对AF产生影响
android·开发语言·kotlin
hai_android1 天前
FusibleFlow:Kotlin Flow 的融合机制原理
android·kotlin
alexhilton1 天前
从零开始的架构测试套件
android·kotlin·android jetpack
YB13751 天前
kotlin 关键字data
kotlin
YB13753 天前
kotlin 关键字expect/actual的作用
kotlin
Android打工仔3 天前
不要再把 Flow 当作一个容器
android·kotlin
天空之城--4 天前
Android行业一周动态:编码趋势与行业资讯汇总
android·性能优化·架构·kotlin·android jetpack