How to filter a list of objects in Scala

1 Answer

0 votes
case class Person(name: String, age: Int)

val people = List(Person("Zephyr", 30), Person("Luminous", 25), Person("Wanderlust", 19), Person("Nebula", 43))

val result = people.filter(_.age >= 30)

println(result)




/*
run:
   
List(Person(Zephyr,30), Person(Nebula,43))
 
*/

 



answered May 5, 2025 by avibootz
...