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

相关推荐
Kapaseker17 小时前
破坏性更新 - 解读 Jetpack Compose 1.12
android·kotlin
Android-Flutter1 天前
android LeakCanary 工作原理 详解
android·kotlin
Android-Flutter1 天前
android 自定义view 详解
android·kotlin
Android打工仔1 天前
从 finally 理解程序的控制流:它为什么不是 catch 后面的代码?
android·kotlin
YXL1111YXL1 天前
续体和状态机 —— suspend 函数的 CPS 变换
android·kotlin
alexhilton1 天前
千万别误用Android Skills
android·kotlin·android jetpack
必须会一定会1 天前
GLM-5.3 迁移实战:强制思考、1M 上下文与官方编程基准
android·开发语言·kotlin
阿pin2 天前
Android随笔-kotlin withContext
android·kotlin·withcontext
Android-Flutter2 天前
android 动画详解
android·kotlin
Android-Flutter2 天前
android WMS 详解(二)
android·kotlin