Scala TreeSet apply() method with example Last Updated : 02 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala TreeSet class, the apply() method is utilized to check if some element is present in the TreeSet or not. Method Definition: def apply(elem: A): Boolean Return Type: It returns true if the given element is present in the TreeSet or else returns false. Example #1: Scala // Scala program of apply() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet(2, 1, 3, 4, 5) // Print the TreeSet println(t1) // Applying apply() method val result = t1.apply(3) // Displays output println("TreeSet contains '3': " + result) } } Output: TreeSet(1, 2, 3, 4, 5) TreeSet contains '3': true Example #2: Scala // Scala program of apply() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet(2, 1, 3, 4, 5) // Print the TreeSet println(t1) // Applying apply() method val result = t1.apply(0) // Displays output println("TreeSet contains '0': " + result) } } Output: TreeSet(1, 2, 3, 4, 5) TreeSet contains '0': false Comment More infoAdvertise with us Next Article Scala TreeSet apply() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set apply() method with example The apply() method is utilized to test if some elements are exist in the set. Method Definition: def apply(elem: A) Return Type: It returns true if some elements are present in the set else it returns false. Example #1: Scala // Scala program of apply() // method // Creating object object GfG { // M 1 min read Scala SortedSet apply() method with example The apply() method is utilized to test if some elements are exist in the SortedSet. Method Definition: def apply(elem: A) Return Type: It returns true if some elements are present in the SortedSet else it returns false. Example #1: Scala // Scala program of apply() // method import scala.collection. 1 min read Scala TreeSet -() method with example In Scala TreeSet class, the -() method is utilized to remove an element from the given TreeSet. Method Definition: def -(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an element removed from the given TreeSet. Example #1: Scala // Scala program of -() // method // Import TreeSet im 1 min read Scala TreeSet drop() method with example In Scala TreeSet class, the drop() method is utilized to drop the first ânâ elements of the TreeSet. Method Definition: def drop(n: Int): TreeSet[A] Return Type: It returns a new TreeSet with all the elements except the first ânâ ones. Example #1: Scala // Scala program of drop() // method // Import 2 min read Scala Stack apply() method with example In Scala Stack class, the apply() method is utilized to return an element at a given position in the stack. The top of the stack corresponds to the element at 0th position and so on. Method Definition: def apply(idx: Int): A Return Type: It returns an element at a given position in the stack. Exampl 1 min read Like