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

相关推荐
唐青枫1 小时前
Kotlin interface 详解:别再把接口写成空壳和万能开关
kotlin
dalong105 小时前
Savitzky-Golay 的C# 实现
开发语言·kotlin·c#
Android-Flutter8 小时前
kotlin 协程 - 核心概念
android·kotlin
Android-Flutter18 小时前
为什么说ActivityThread是主线程?
android·kotlin
学习使我健康1 天前
一个基于 **Jetpack Compose + Material 3** 的 Android 入门示例项目,演示 Compose 声明式 UI 的核心用法
ui·kotlin·android jetpack
alexhilton2 天前
Android XR 开发入门完全指南
android·kotlin·android jetpack
我命由我123453 天前
匈牙利命名法
java·服务器·后端·学习·java-ee·kotlin·学习方法
3 天前
Android 自定义 View 实战:从零打造工业级全向摇杆控件(OmniJoystickView)
android·kotlin·自定义view·摇杆控件
雨白3 天前
深入理解 Kotlin 协程 (十一):以逸待劳,探秘 select 多路复用与并发安全策略
android·kotlin
刘名喜3 天前
第22篇-数据库迁移-Liquibase
kotlin·springboot