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

相关推荐
赏金术士1 天前
Kotlin 习题集 · 高级篇
android·开发语言·kotlin
pengyu2 天前
【Kotlin 协程修仙录 · 金丹境 · 中阶】 | 启动密法:CoroutineStart 四种模式与底层调度玄机
android·kotlin
UXbot2 天前
AI一次生成iOS和Android双端原型功能详解
android·前端·ios·kotlin·交互·swift
赏金术士2 天前
Kotlin 习题集 · 进阶篇
java·数据库·kotlin
赏金术士2 天前
Kotlin 习题集 · 基础篇
android·开发语言·kotlin
Kapaseker2 天前
最简单的 Compose 动画 — animateDpAsState
android·kotlin
赏金术士2 天前
Kotlin ViewModel
android·kotlin
vistaup2 天前
kotlin 二维码实现高斯模糊
android·kotlin
6666v63 天前
深入 Android 统一状态模型:MVI 架构的核心实现
android·kotlin
idingzhi3 天前
A股量化策略日报(2026年05月11日)
android·开发语言·python·kotlin