Scala Mutable SortedSet filter() method Last Updated : 26 Mar, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Scala // Scala program of filter() // method import scala.collection.mutable.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.mutable.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 Mutable SortedSet intersect() method S Shivam_k Follow Improve Article Tags : Scala Scala Scala-Method Scala mutable-sortedset Similar Reads Scala Mutable SortedSet init() method In Scala mutable collections, SortedSet 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() // me 1 min read Scala Mutable SortedSet find() method In Scala mutable collections, SortedSet 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 give 1 min read Scala Mutable SortedSet intersect() method In Scala mutable collections, SortedSet The intersect() method is utilized to compute the intersection between two SortedSets. Method Definition: def intersect(that: SortedSet[A]): SortedSet[A] Return Type: It returns a SortedSet containing the elements present in both the SortedSets. Example #1: Sc 1 min read Scala Mutable SortedSet -() method In Scala mutable collections, SortedSet -() method is utilized to creates a new SortedSet with a given element removed from the SortedSet. Method Definition: def -(elem: A): SortedSet[A] Return Type: It returns a new SortedSet with a given element removed from the SortedSet. Example #1: Scala // Sca 1 min read Scala Mutable SortedSet +() method In Scala mutable collections, +() method is utilized to create a new SortedSet with an additional element unless the element is already present. Method Definition: def +(elem: A): SortedSet[A] Return Type: It returns a new SortedSet with an additional element unless the element is already present. E 1 min read Scala Mutable SortedSet forall() method In Scala mutable collections, SortedSet forall() method is utilized to check if the given predicate satisfies all the elements of the SortedSet or not. Method Definition: def forall(p: (A) => Boolean): Boolean Return Type: It returns true if the stated predicate holds true for all the elements of 1 min read Like