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

相关推荐
前行的小黑炭12 小时前
Android :为APK注入“脂肪”,论Android垃圾代码在安全加固中的作用
android·kotlin
tangweiguo0305198713 小时前
Android Kotlin 动态注册 Broadcast 的完整封装方案
android·kotlin
前行的小黑炭14 小时前
Android 不同构建模式下使用不同类的例子:如何在debug模式和release模式,让其使用不同的类呢?
android·kotlin·gradle
Android-Flutter16 小时前
kotlin - 2个Fragment实现左右显示,左边列表,右边详情,平板横、竖屏切换
android·kotlin
木头左1 天前
结合机器学习的Backtrader跨市场交易策略研究
人工智能·机器学习·kotlin
前行的小黑炭2 天前
Android Flow的其他使用:stateIn和冷流(普通Flow)
android·kotlin
前行的小黑炭2 天前
Android Flow:你真的了解?在工作当中的运用~~通过光照例子来解释一下..
android·kotlin
张可3 天前
Kotlin 函数式编程思想
android·前端·kotlin
alexhilton3 天前
Android ViewModel数据加载:基于Flow架构的最佳实践
android·kotlin·android jetpack
初始化3 天前
Android 页面代码粒度化管理进阶
android·kotlin