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

相关推荐
6666v613 小时前
Android Kotlin(2) 协程上下文与异常处理机制
kotlin
zhangphil17 小时前
Kotlin协程await与join挂起函数异同
kotlin
儿歌八万首18 小时前
Android 自定义 View 实战:打造一个跟随滑动的丝滑指示器
android·kotlin
4Forsee19 小时前
【Kotlin】Kotlin 基础语法:变量、控制和函数
kotlin
Propeller1 天前
【Kotlin】Kotlin 基础语法:变量、控制和函数
kotlin
Rysxt_2 天前
Kotlin前景深度分析:市场占有、技术优势与未来展望
android·开发语言·kotlin
莫白媛2 天前
Android开发之Kotlin 在 Android 开发中的全面指南
android·开发语言·kotlin
天勤量化大唯粉3 天前
基于距离的配对交易策略:捕捉价差异常偏离的均值回归机会(天勤量化代码实现)
android·开发语言·python·算法·kotlin·开源软件·策略模式
hudawei9963 天前
kotlin冷流热流的区别
android·开发语言·kotlin·flow··冷流·热流
hudawei9963 天前
对比kotlin和flutter中的异步编程
开发语言·flutter·kotlin·异步·