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

相关推荐
plainGeekDev3 小时前
Gradle 写法 → Kotlin DSL
android·java·kotlin
Android-Flutter1 天前
android compose shadow 阴影 使用
android·kotlin·compose
Android-Flutter2 天前
android compose 自定义Painter绘制图形 使用
android·kotlin·compose
Android-Flutter2 天前
android compose Brush 渐变和着色器 使用
android·kotlin·compose
Flynt2 天前
Room 3.0 包名重构 + KMP 迁移:我把项目升级踩了个遍
android·数据库·kotlin
TechNomad2 天前
Kotlin函数详解与使用示例
android·kotlin
alexhilton3 天前
将应用迁移到Navigation 3:痛点、加班和紧急修复
android·kotlin·android jetpack
唐青枫3 天前
Kotlin 运算符重载详解:为什么 a += b 有时改对象,有时换对象?
kotlin
plainGeekDev3 天前
Gson → kotlinx.serialization
android·java·kotlin