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

相关推荐
zh_xuan12 小时前
kotlin定义函数和变量
android·开发语言·kotlin
Android-Flutter21 小时前
Compose - Scaffold使用
android·kotlin
zh_xuan1 天前
kotlin的常见空检查
android·开发语言·kotlin
quanyechacsdn2 天前
Android Studio创建库文件用jitpack构建后使用implementation方式引用
android·ide·kotlin·android studio·implementation·android 库文件·使用jitpack
Huang兄2 天前
kotlin协程-官方框架
kotlin
Huang兄2 天前
kotlin协程-基础设施篇-函数的挂起
kotlin
Kapaseker2 天前
你不看会后悔的2025年终总结
android·kotlin
alexhilton2 天前
务实的模块化:连接模块(wiring modules)的妙用
android·kotlin·android jetpack
幽络源小助理3 天前
下载安装AndroidStudio配置Gradle运行第一个kotlin程序
android·开发语言·kotlin