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

相关推荐
只可远观13 小时前
Android 自动埋点(页面打开 / 关闭 + 点击事件)完整方案
android·kotlin
aqi0016 小时前
FFmpeg开发笔记(一百零二)国产的音视频移动开源工具FFmpegAndroid
android·ffmpeg·kotlin·音视频·直播·流媒体
阿巴斯甜18 小时前
子协程的异常传播(CoroutineExceptionHandler ):
kotlin
alexhilton1 天前
Android上的ZeroMQ:用发布/订阅模式连接Linux服务
android·kotlin·android jetpack
Fate_I_C2 天前
View Binding的基础使用
android·kotlin·viewbinding
zhangphil2 天前
Android Coil 3 extend ImageRequest‘s custom method/function,Kotlin
android·kotlin
Empty-Filled2 天前
Prompt改版后怎么回归:一套测试集和评分方法
回归·kotlin·prompt
阿巴斯甜2 天前
launch 和 async 内部都是串行,为什么还能实现并发?
kotlin
古怪今人2 天前
Gradle构建工具 Groovy/Kotlin DSL的现代化自动化构建工具
开发语言·kotlin·自动化
赏金术士2 天前
Kotlin 协程与挂起函数(Coroutines & suspend)入门到实战
android·开发语言·kotlin