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

相关推荐
Kapaseker2 小时前
一文吃透 Kotlin 集合操作符
android·kotlin
plainGeekDev21 小时前
Activity 间传值 → Navigation 参数
android·java·kotlin
plainGeekDev21 小时前
onActivityResult → ActivityResult API
android·java·kotlin
alexhilton2 天前
Android车载OS中的Remote Compose
android·kotlin·android jetpack
plainGeekDev2 天前
广播接收器 → Flow + Lifecycle
android·java·kotlin
plainGeekDev2 天前
EventBus → SharedFlow
android·java·kotlin
Kapaseker3 天前
学不动了,入门 Compose Styles API
android·kotlin
plainGeekDev4 天前
MVC 写法 → MVVM
android·java·kotlin
plainGeekDev5 天前
单例模式 → object 声明
android·java·kotlin
rocpp6 天前
Android 多语言切换实战:从 Context 到 Android 13 应用语言适配
android·kotlin