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

相关推荐
alexhilton21 小时前
如何用Perfetto来对启动优化去伪存真
android·kotlin·android jetpack
赏金术士1 天前
Kotlin 从入门到进阶 之函数模块(核心基础)(二)
android·开发语言·kotlin
赏金术士1 天前
Kotlin 从入门到进阶 之作用域函数 & 优雅写法(五)
android·开发语言·kotlin
赏金术士1 天前
Kotlin 从入门到进阶 之协程 Flow 模块(九)
开发语言·kotlin·php
JohnnyDeng941 天前
Kotlin 协程原理与 Android 中的最佳实践
android·kotlin·协程
赏金术士1 天前
Kotlin 从入门到进阶 之委托 模块(六)
python·微信·kotlin
帅次1 天前
LazyColumn 懒加载、items 与 key
android·flutter·kotlin·android studio·webview
赏金术士1 天前
Kotlin 从入门到进阶 之泛型 模块(七)
android·开发语言·kotlin
Kapaseker1 天前
不吹牛逼!精通 Compose 绘制(一)
android·kotlin
赏金术士2 天前
Kotlin 从入门到进阶 之异常与标准库(八)
android·开发语言·kotlin