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

相关推荐
用户69371750013843 分钟前
Kotlin 函数详解:命名参数与默认参数值
android·后端·kotlin
Jeled2 小时前
RecyclerView ViewHolder 复用机制详解(含常见错乱问题与优化方案)
android·学习·面试·kotlin
柯南二号4 小时前
【大前端】【Android】 Kotlin 语法超详细解析(2025 最新)
android·kotlin
Ya-Jun15 小时前
项目实战Now in Android:项目模块说明
android·架构·kotlin
消失的旧时光-194321 小时前
Kotlinx.serialization 使用指南
android·kotlin·json
消失的旧时光-19431 天前
Kotlinx.serialization 项目集成
android·kotlin·json
彭同学学习日志1 天前
解决 Android Navigation 组件导航栏配置崩溃:从错误到实现的完整指南
android·kotlin
怪兽20141 天前
fastjson在kotlin不使用kotlin-reflect库怎么使用?
android·开发语言·kotlin
ClearLiang1 天前
Kotlin-协程的挂起与恢复
开发语言·kotlin
彭同学学习日志1 天前
Kotlin Fragment 按钮跳转报错解决:Unresolved reference ‘floatingActionButton‘
android·开发语言·kotlin