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

相关推荐
plainGeekDev1 天前
libs 目录 → Gradle 依赖管理
android·java·kotlin
监督者修1 天前
从零构建 GIS 数据引擎:方案驱动架构的设计与实践
android·架构·kotlin
urkay-2 天前
Kotlin Flow分类
android·开发语言·kotlin
alexhilton3 天前
Kotlin DSL深度解析:从Gradle脚本到构建你自己的DSL
android·kotlin·android jetpack
Kapaseker3 天前
Android 开放这扇门,正在被 Google 从里面反锁
android·kotlin
唐青枫3 天前
别再把 Util 类堆成杂物间:Kotlin Extension 扩展函数与扩展属性实战详解
kotlin
plainGeekDev4 天前
依赖管理 → Version Catalog
android·java·kotlin
黄林晴4 天前
KMP 正式支持 SwiftPM:CocoaPods 迁移配置指南
android·ios·kotlin
花燃柳卧5 天前
跨平台路由组件工程源码补充上传
android·flutter·kotlin
TechNomad5 天前
Kotlin类对象与接口详解
android·kotlin