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

相关推荐
来来走走14 小时前
Android开发(Kotlin) 扩展函数和运算符重载
android·开发语言·kotlin
wuwu_q14 小时前
用通俗易懂 + Android 开发实战的方式,详细讲解 Kotlin Flow 中的 retryWhen 操作符
android·开发语言·kotlin
li-jia-wei16 小时前
我在造一个编程语言,叫 Free
kotlin
Android-Flutter18 小时前
kotlin - 显示HDR图(heic格式),使用GainMap算法,速度从5秒提升到0.6秒
android·kotlin
雨白18 小时前
协程进阶:协作、互斥与共享状态管理
android·kotlin
studyForMokey2 天前
【Kotlin内联函数】
android·开发语言·kotlin
Larry_zhang双栖2 天前
Flutter Android Kotlin 插件编译错误完整解决方案
android·flutter·kotlin
wuwu_q2 天前
彻底讲清楚 Kotlin 的 when 表达式
android·开发语言·kotlin
QING6182 天前
Jetpack Compose 条件布局与 Layout 内在测量详解
android·kotlin·android jetpack
Kapaseker2 天前
在 Compose 中使用 SurfaceView
android·kotlin