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

相关推荐
Kapaseker16 分钟前
5 分钟搞懂 Kotlin DSL
android·kotlin
alexhilton1 天前
使用Android Archive进行打包
android·kotlin·android jetpack
逐光老顽童3 天前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin
plainGeekDev4 天前
null 判断 → Kotlin 可空类型
android·java·kotlin
plainGeekDev4 天前
getter/setter → Kotlin 属性
android·java·kotlin
Junerver4 天前
我写了一个 Compose Multiplatform 组件库,你可能会用到
kotlin·android jetpack
Ehtan_Zheng5 天前
Kotlin const val vs val:字节码、性能与隐藏陷阱详解
android·kotlin
zhangphil5 天前
大日志文件截取,从指定日志文件中提取两个标记字符串之间的全部内容,Kotlin
kotlin
朝星5 天前
Android开发[14]:网络优化之OkHttp
android·okhttp·kotlin
AI浩5 天前
模型剪枝与稀疏推理:结构化、非结构化、2:4 稀疏与大模型压缩(分层式精讲)
android·kotlin·剪枝