Scala TreeSet diff() method with example Last Updated : 21 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The diff() method is used to find the difference between the two TreeSet. It deletes elements that are present in one TreeSet from the other one. Method Definition: def diff[B >: A](that: collection.Seq[B]): TreeSet[A] Return Type: It returns a new TreeSet which consists of elements after the difference between the two given TreeSet. Example #1: Scala // Scala program of diff() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet(1, 2, 3, 4, 5) val t2 = TreeSet(3, 4, 5) // Print the TreeSet println("TreeSet_1: " + t1) println("TreeSet_2: " + t2) // Applying diff method val result = t1.diff(t2) // Displays output print("(TreeSet_1 - TreeSet_2): " + result) } } Output: TreeSet_1: TreeSet(1, 2, 3, 4, 5) TreeSet_2: TreeSet(3, 4, 5) (TreeSet_1 - TreeSet_2): TreeSet(1, 2) Example #2: Scala // Scala program of diff() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet(1, 2, 3, 4, 5) val t2 = TreeSet(3, 4, 5, 6, 7, 8) // Print the TreeSet println("TreeSet_1: " + t1) println("TreeSet_2: " + t2) // Applying diff method val result = t2.diff(t1) // Displays output print("(TreeSet_2 - TreeSet_1): " + result) } } Output: TreeSet_1: TreeSet(1, 2, 3, 4, 5) TreeSet_2: TreeSet(3, 4, 5, 6, 7, 8) (TreeSet_2 - TreeSet_1): TreeSet(6, 7, 8) Comment More infoAdvertise with us Next Article Scala TreeSet diff() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set diff() method with example The diff() method is utilized to compute the difference of a set and an another set. Method Definition: def diff(that: Set[A]): Set[A] Return Type: It returns a set which is the difference between two sets. Example #1: Scala // Scala program of diff() // method // Creating object object GfG { // Mai 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 SortedSet diff() method with example The diff() method is utilized to compute the difference of a SortedSet and an another SortedSet. Method Definition: def diff(that: SortedSet[A]): SortedSet[A] Return Type: It returns a SortedSet which is the difference between two SortedSets. Example #1: Scala // Scala program of diff() // method im 1 min read Scala TreeSet &~() method with example In Scala TreeSet class, the &~() method is utilized to return a new TreeSet which contains the difference between two TreeSets. Method Definition: def &~(that: TreeSet[A]): TreeSet[A] Return Type: It returns a new TreeSet which contains the difference between two TreeSets. Example #1: Scala 2 min read Scala Stack diff() method with example In Scala Stack class, the diff() method is used to find the difference between the two stacks. It deletes elements that are present in one stack from the other one. Method Definition: def diff[B >: A](that: collection.Seq[B]): Stack[A] Return Type: It returns a new stack which consists of element 2 min read Like