Scala SortedSet filter() method with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The 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: Scala // Scala program of filter() // method import scala.collection.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedSet val s1 = SortedSet(5, 12, 3, 13) // Applying filter method val result = s1.filter(_ < 10) // Displays output println(result) } } Output: TreeSet(3, 5) Example #2: Scala // Scala program of filter() // method import scala.collection.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedSet val s1 = SortedSet(5, 12, 3, 13) // Applying filter method val result = s1.filter(_ < 3) // Displays output println(result) } } Output: TreeSet() Comment More infoAdvertise with us Next Article Scala SortedSet filter() method with example G gopaldave Follow Improve Article Tags : Scala Scala-Method scala-collection Similar Reads Scala TreeSet filter() method with example In Scala TreeSet class, the filter() method is utilized to return a new TreeSet that consists of all the elements that satisfy a given predicate. Method Definition: def filter(pred: (A) => Boolean): TreeSet[A] Return Type: It returns a new TreeSet that consists of all the elements that satisfy a 2 min read Scala SortedMap filter() method with example The filter() method is utilized to select all elements of the SortedMap which satisfies a stated predicate. Method Definition: def filter(p: ((A, B))=> Boolean): SortedMap[A, B] Return Type: It returns a new SortedMap consisting all the elements of the SortedMap which satisfies the given predicat 1 min read Scala SortedSet init() method with example The init() method is utilized to find all the elements of the SortedSet except the last one. Method Definition: def init: SortedSet[A] Return Type: It returns all the elements of the SortedSet except the last one. Example #1: Scala // Scala program of init() // method import scala.collection.immutab 1 min read Scala SortedSet find() method with example The find() method is utilized to find the first element of the SortedSet that satisfies the given predicate if present. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element of the SortedSet which satisfies the given predicate. Example #1: Scala // Sc 1 min read Scala Set filter() method with example 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: Scala // Scala progr 1 min read Like