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

相关推荐
Android打工仔6 小时前
Kotlin 协程源码解析(五):BaseContinuationImpl.resumeWith() —— Continuation 链是如何被展开的?
android·kotlin
Android-Flutter7 小时前
android Glide 源码流程分析
android·kotlin
Android-Flutter7 小时前
android Glide 使用详解
android·kotlin
小陈的进阶之路9 小时前
Claude Code辅助测试:API测试与pytest自动化
android·开发语言·kotlin
alexhilton1 天前
规范驱动开发:让AI生成符合预期的KMP代码
android·kotlin·android jetpack
Android-Flutter1 天前
android 性能优化 详解
android·kotlin
Android-Flutter2 天前
android kotlin launch 源码分析
android·kotlin
Android-Flutter2 天前
android kotlin 状态机 Continuation 详解
android·kotlin
蜡台3 天前
Jetpack Compose 从入门到精通
android·前端·kotlin·compose·jepack
蜡台3 天前
Jetpack Compose 核心:状态管理 + Lazy 列表
android·kotlin·state·jetpack compose