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

相关推荐
fundroid6 小时前
Kotlin 协程:Channel 与 Flow 深度对比及 Channel 使用指南
android·kotlin·协程
移动开发者1号9 小时前
深入理解原子类与CAS无锁编程:原理、实战与优化
android·kotlin
移动开发者1号9 小时前
深入理解 ThreadLocal:原理、实战与优化指南
android·kotlin
Devil枫13 小时前
Kotlin高级特性深度解析
android·开发语言·kotlin
ChinaDragonDreamer13 小时前
Kotlin:2.1.20 的新特性
android·开发语言·kotlin
每次的天空1 天前
Android-自定义View的实战学习总结
android·学习·kotlin·音视频
移动开发者1号2 天前
使用 Android App Bundle 极致压缩应用体积
android·kotlin
移动开发者1号2 天前
构建高可用线上性能监控体系:从原理到实战
android·kotlin
恋猫de小郭2 天前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
androidwork2 天前
深入解析内存抖动:定位与修复实战(Kotlin版)
android·kotlin