Kotlin filterIsInstance filterNotNull forEach

Kotlin filterIsInstance filterNotNull forEach

Kotlin 复制代码
fun main(args: Array<String>) {
    val i1 = MyItem(1, 1)
    val i2: MyItem? = null
    val i3: Int = 3
    val i4 = "4"
    val i5 = null
    val i6 = MyItem(6, 6)

    val list = mutableListOf<Any?>(i1, i2, i3, i4, i5, i6)
    list.filterIsInstance(MyItem::class.java).forEach {
        println(it)
    }

    println("---")

    list.filterNotNull().forEach {
        println(it)
    }
}

class MyItem {
    private var id = -1
    private var pos = -1

    constructor(id: Int, pos: Int) {
        this.id = id
        this.pos = pos
    }

    override fun toString(): String {
        return "id=${id} pos=${pos}"
    }
}

id=1 pos=1

id=6 pos=6


id=1 pos=1

3

4

id=6 pos=6

Kotlin HashMap entries.filter过滤forEach_kotlin map.entries.foreach-CSDN博客文章浏览阅读997次。一、flow ,emit,onCompletion,collect。四、map,重组改写数据。八、conflate 合并。九、debounce去重。二、函数作为flow。kotlin协程flow filter map flowOn zip combine(1)_zhangphil的博客-CSDN博客。_kotlin map.entries.foreachhttps://blog.csdn.net/zhangphil/article/details/133990762

相关推荐
JMchen1239 小时前
Jetpack 内核实战(九):实战(上)——记事本首页列表 + 搜索功能开发
kotlin·android 实战·记事本 app 开发·recyclerview 优化·jetpack 综合实战
pengyu11 小时前
【Kotlin 协程修仙录 · 炼虚境 · 初阶】 | 虚空造物:Channel 基础与协程间通信的管道艺术
android·前端·kotlin
小强闯江湖11 小时前
ViewCompose:让原生 Android View 进入声明式时代
android·开源·kotlin
雨白15 小时前
Kotlin 委托机制:搞懂“老板与秘书”模式
kotlin
pengyu2 天前
【Kotlin 协程修仙录 · 化神境 · 后阶】 | 异常天劫:Flow 异常处理的终极奥义与重试之道
android·kotlin
pengyu2 天前
【Kotlin 协程修仙录 · 化神境 · 中阶】 | 多播奥义:SharedFlow 高级配置与 Channel 的抉择之道
android·kotlin
撩得Android一次心动2 天前
Kotlin 语言【知识点整理2】
android·开发语言·kotlin
Android打工仔3 天前
Kotlin 协程源码解析(五):BaseContinuationImpl.resumeWith() —— Continuation 链是如何被展开的?
android·kotlin
Android-Flutter3 天前
android Glide 源码流程分析
android·kotlin
Android-Flutter3 天前
android Glide 使用详解
android·kotlin