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

相关推荐
赏金术士20 小时前
Kotlin 数据流与单双向绑定
android·开发语言·kotlin
帅次1 天前
Modifier 链与顺序、测量与命中区域
android·kotlin·compose·modifier
小仙女喂得猪1 天前
2026 Android 组件化项目的AICoding落地实践
android·kotlin·ai编程
帅次1 天前
状态 StateFlow、ViewModel 与 UI 收集
android·kotlin·gradle·android studio·android jetpack
Kapaseker1 天前
Android 中的 MVVM 是如何构建起来的
android·kotlin
雨白2 天前
深入理解 Kotlin 协程 (六):进退有度,解密协程取消响应与异常分发机制
kotlin
百锦再2 天前
Auto.js变成基础知识学习
开发语言·javascript·学习·sqlite·kotlin·android studio·数据库开发
帅次2 天前
Compose 入门:@Composable、组合与重组
android·kotlin·gradle·android jetpack·compose·composable
Junerver2 天前
Kotlin - 约定contract
kotlin
Junerver2 天前
使用datetime更加优雅地在kotlin中处理时间
kotlin