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

相关推荐
alexhilton4 小时前
为什么你的 LazyColumn 仍然卡顿
android·kotlin·android jetpack
mmsx1 天前
Android 防二次打包第一道锁:签名校验与完整性校验
android·kotlin
mmsx1 天前
Android 混淆不等于安全:二次打包链路完整走一遍
android·kotlin
墨天梦1 天前
D05_ViewModel与单向数据流
android·kotlin
墨天梦2 天前
D03_Compose列表与稳定身份
android·gitee·kotlin
萌新杰少2 天前
Kuikly股票查看软件开发体验——SaiRen
android·kotlin·客户端
用户92817267390162 天前
Android Compose版本的AI组件库来了。
android·kotlin
墨天梦2 天前
B19_SunnyWeather到阅读客户端
android·kotlin
墨天梦3 天前
B17_LifecycleLiveData与Flow
android·kotlin
熊猫钓鱼>_>4 天前
Kotlin Multiplatform for OpenHarmony 实战:为 Landscapist 实现图片加载适配
开发语言·kotlin·华为云·ai编程·harmonyos·鸿蒙·openharmony