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

相关推荐
铉铉这波能秀22 分钟前
如何在Android Studio中使用Gemini进行AI Coding
android·java·人工智能·ai·kotlin·app·android studio
爱学啊1 天前
3.Android Compose 基础系列:在 Kotlin 中创建和使用函数
kotlin·compose·android compose开发基础
低调小一1 天前
LRU缓存科普与实现(Kotlin 与 Swift)
开发语言·缓存·kotlin
雨白1 天前
深入理解协程的运作机制 —— 调度、挂起与性能
android·kotlin
xqlily1 天前
Kotlin:现代编程语言的革新者
android·开发语言·kotlin
消失的旧时光-19431 天前
人脸跟随 ( Channel 实现(缓存5条数据 + 2度过滤 + 平滑移动))
android·java·开发语言·kotlin
消失的旧时光-19432 天前
Android回退按钮处理方法总结
android·开发语言·kotlin
VIjolie2 天前
协程CoroutineContext理解
kotlin
alexhilton3 天前
突破速度障碍:非阻塞启动画面如何将Android 应用启动时间缩短90%
android·kotlin·android jetpack