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

相关推荐
沅霖2 小时前
Android Studio Java工程开发环境,怎么切换到Kotlin开发环境
android·kotlin·android studio
Kapaseker2 小时前
Kotlin SharedFlow 的三个参数到底有啥用
android·kotlin
阿巴斯甜3 小时前
by 和by lazy 懒加载
kotlin
三少爷的鞋5 小时前
Android 架构系列之MVVM 和 MVI 算架构吗?
android·kotlin
只可远观1 天前
Android 自动埋点(页面打开 / 关闭 + 点击事件)完整方案
android·kotlin
aqi001 天前
FFmpeg开发笔记(一百零二)国产的音视频移动开源工具FFmpegAndroid
android·ffmpeg·kotlin·音视频·直播·流媒体
阿巴斯甜1 天前
子协程的异常传播(CoroutineExceptionHandler ):
kotlin
alexhilton2 天前
Android上的ZeroMQ:用发布/订阅模式连接Linux服务
android·kotlin·android jetpack
Fate_I_C2 天前
View Binding的基础使用
android·kotlin·viewbinding
zhangphil2 天前
Android Coil 3 extend ImageRequest‘s custom method/function,Kotlin
android·kotlin