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 小时前
Glide 该换了?Coil:Kotlin 时代的图片加载库
android·开源·kotlin
plainGeekDev3 小时前
Android内存面试题:OOM都解决不了,性能优化从何谈起?
android·面试·kotlin
疏狂难除9 小时前
JetBrains IDE插件开发教程(二)——学习初始代码
ide·kotlin
plainGeekDev10 小时前
Kotlin协程面试题:suspend原理都说不清,协程你真会用?
android·面试·kotlin
赏金术士1 天前
第六章:UI组件与Material3主题
android·ui·kotlin·compose
赏金术士1 天前
Jetpack Compose 底部导航实战教程(完整版)
android·kotlin·compose
Honker_yhw1 天前
大数据管理与应用系列丛书《数据挖掘》(吕欣等著)读书笔记-LASSO回归
数据挖掘·回归·kotlin
程序员煊子2 天前
用 Cursor 从零搭一个 Compose 本地记账 App:实战记录与源码解析
android·kotlin·compose·cursor
alexhilton2 天前
面向Android开发者的Google I/O 2026
android·kotlin·android jetpack
idingzhi2 天前
A股量化策略日报(2026年05月22日)
android·开发语言·python·kotlin