In Scala mutable collections, SortedSet filter() method is utilized to select all elements of the SortedSet which satisfies a stated predicate.
Method Definition: def filter(p: (A) => Boolean): SortedSet[A]
Return Type: It returns a TreeSet containing all the elements of the SortedSet which satisfies the given predicate.
Example #1:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 5 , 12 , 3 , 13 )
val result = s 1 .filter( _ < 10 )
println(result)
}
}
|
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 5 , 12 , 3 , 13 )
val result = s 1 .filter( _ < 3 )
println(result)
}
}
|