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

相关推荐
传奇开心果编程1 天前
【Jetpack Compose娓娓道来】第44课:持久化——让数据“关掉App也不丢”
android·kotlin·移动开发·数据持久化·jetpack compose·ui框架·声明式ui
OriginCoding2 天前
一个 JDK 跑起六个分布式挑战:Kotlin 版 Gossip Glomers(一)
分布式·kotlin
alexhilton3 天前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack
金銀銅鐵6 天前
一个 4 个常量的枚举,Kotlin 在字节码里生成了什么
jvm·kotlin
Easyhood8 天前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
松仔log8 天前
Kotlin中级——callbackFlow
java·前端·kotlin
zh_xuan8 天前
kotlin常见面试题
开发语言·kotlin·面试题
mmsx8 天前
耳切法切带洞多边形:论文能跑通,真实数据为什么崩
android·kotlin
Kapaseker8 天前
Kotlin 又要加语法糖了:这次轮到 if-else
android·kotlin