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

相关推荐
Kapaseker7 小时前
如果我要从 List 中获取一段元素
android·kotlin
alexhilton18 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
a1117761 天前
中文优先的企业 RAG 知识库 开源项目
开发语言·开源·kotlin
Android-Flutter1 天前
Kotlin 冷流与热流详解
android·kotlin
Android-Flutter1 天前
OkHttp 总结
android·okhttp·kotlin
Kapaseker3 天前
别再只用 Loading、Success、Error 表示所有页面状态了
android·kotlin
雨白4 天前
深入理解 Kotlin 协程 (九):互通有无,解构 Channel 缓冲策略与底层无锁机制
android·kotlin
蜡台5 天前
Android WebView 设计指南
android·java·kotlin
Kapaseker5 天前
深入理解 Compose 副作用
kotlin
雨白6 天前
深入理解 Kotlin 协程 (八):拾遗补阙,探秘官方框架的调度细节与取消闭环
android·kotlin