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

相关推荐
hai_android4 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
传奇开心果编程5 天前
【Jetpack Compose娓娓道来】第44课:持久化——让数据“关掉App也不丢”
android·kotlin·移动开发·数据持久化·jetpack compose·ui框架·声明式ui
OriginCoding6 天前
一个 JDK 跑起六个分布式挑战:Kotlin 版 Gossip Glomers(一)
分布式·kotlin
alexhilton6 天前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack
金銀銅鐵10 天前
一个 4 个常量的枚举,Kotlin 在字节码里生成了什么
jvm·kotlin
Easyhood11 天前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
松仔log12 天前
Kotlin中级——callbackFlow
java·前端·kotlin
zh_xuan12 天前
kotlin常见面试题
开发语言·kotlin·面试题
mmsx12 天前
耳切法切带洞多边形:论文能跑通,真实数据为什么崩
android·kotlin
Kapaseker12 天前
Kotlin 又要加语法糖了:这次轮到 if-else
android·kotlin