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

相关推荐
传奇开心果编程5 小时前
【Jetpack Compose娓娓道来】第29课:状态容器与UI事件建模——把“散装状态”变成“可穷举的契约”
android·kotlin·移动开发·android jetpack·ui框架·开发范式·声明式ui
我是唐青枫2 天前
Kotlin Inheritance(继承)详解:语法、原理、实战 Demo
开发语言·kotlin
Goway_Hui2 天前
【KMP for OpenHarmony】-- 在鸿蒙工程中使用 Apollo-Kotlin
华为·kotlin·harmonyos
释厄6233 天前
AI 军备竞赛悖论——为 AI 卖游戏但 AI 需要游戏母场景
人工智能·游戏·kotlin
D e re k ZH3 天前
保序回归:从 PAVA 到可并堆的单调约束优化
c++·算法·数据挖掘·回归·kotlin
Goway_Hui3 天前
【KMP for OpenHarmony】Cache4k 0.14.0 鸿蒙适配
华为·kotlin·harmonyos
YB13753 天前
kotlin与函数式编程
kotlin
我是唐青枫3 天前
Kotlin Delegation 委托详解
开发语言·kotlin
唐青枫4 天前
Kotlin Inheritance(继承)详解:语法、原理、实战 Demo
kotlin
alexhilton4 天前
用Konsist与Lint强制执行设计系统契约
android·kotlin·android jetpack