Scala Set filter() method with example
Last Updated :
18 Oct, 2019
The filter() method is utilized to select all elements of the set which satisfies a stated predicate.
Method Definition: def filter(p: (A) => Boolean): Set[A]
Return Type: It returns a set containing all the elements of the set which satisfies the given predicate.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 5 , 12 , 3 , 13 )
val result = s 1 .filter( _ < 10 )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 5 , 12 , 3 , 13 )
val result = s 1 .filter( _ < 3 )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...