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 小时前
Android开发:用户注册和登录的数据库代码详细解释
android·数据库·kotlin
simplepeng15 小时前
Room 3.0 KMP Alpha-01
android·kotlin·android jetpack
2 天前
深度解析Compose中的BoxWithConstraints
android·kotlin·android jetpack
PokeMa2 天前
[协程]-[详解]-launch与async
kotlin·async·协程·launch·协程构建·源码对比
常利兵2 天前
一文搞懂双Token、SSO与第三方权限打通,附实战代码
python·gitee·kotlin
PokeMa2 天前
[协程]-[详解]-[协程作用域]-viewModelScope
kotlin·协程·源码分析·viewmodelscope·原理分析·协程作用域
新缸中之脑2 天前
使用 AI 进行科学调试
android·人工智能·kotlin
QING6182 天前
Android Gradle Plugin 9.0 升级指南:告别十年技术债,你准备好了吗?
android·kotlin·gradle
Kapaseker2 天前
一杯美式理解 Inner Class
android·kotlin