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

相关推荐
蜡台2 小时前
Kotlin 零基础完整版实战教程|从语法入门到Android工程实战
android·开发语言·kotlin
蜡台5 小时前
Kotlin 五大作用域函数详解|let/run/apply/also/with 选型指南+实战避坑
android·java·kotlin
hai_android8 小时前
Messenger:Android 最轻量的 IPC 方式
android·kotlin
hai_android1 天前
不用 AIDL,手把手教你手写 Binder 代理类
android·kotlin
雨白1 天前
Kotlin 泛型进阶:攻克型变与实化,直击痛点
kotlin
alexhilton1 天前
架构测试为何需要双视图
android·kotlin·android jetpack
事圆则缓1 天前
Jetpack Compose 快速上手
android·kotlin
事圆则缓1 天前
MVC、MVP、MVVM、MVI 的区别与实现原理
android·kotlin·mvc
事圆则缓1 天前
Android组件化指南
android·kotlin
事圆则缓1 天前
Jetpack Compose Effect 完全指南
android·kotlin