📜  kotlin 过滤器不为空 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:32.551000             🧑  作者: Mango

代码示例1
fun main() {
    val asha = Student(101, "Asha")
    val afra = Student(103, "Afra")
    val studentList = listOf(asha, null, afra, null)
    val filteredList = studentList.filterNotNull().forEach {  
            println(it) 
    }
}
data class Student(val id: Long, val name: String)