kotlin filter list
fun main() { val asha = Student(101, "Asha") val john = Student(102, "John") val afra = Student(103, "Afra") val kyle = Student(104, "Kyle") val studentList = listOf(asha, john, afra, kyle) val filteredList = studentList.filter { student -> student.name.startsWith("A") } println(filteredList) /* prints [Student(id=101, name=Asha), Student(id=103, name=Afra)] */ } data class Student(val id: Long, val name: String)
Source: tedblob.com
kotlin filter arraylist
fun main() { val numbers = arrayListOf("zero", "one", "two", "three", "four") println(numbers.filter { it -> it.equals("three") }) /* prints [three] */ }
Source: tedblob.com
kotlin list filter example
val studentList = listOf(asha, john, afra, kyle) val filteredList = studentList.filter { student -> student.name.startsWith("A") } println(filteredList)
Source: tedblob.com