Scala SortedSet diff() method with example Last Updated : 03 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 import scala.collection.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating SortedSets val s1 = SortedSet(1, 2, 3, 4, 5) val s2 = SortedSet(1, 2, 3) // Applying diff method val s3 = s1.diff(s2) // Displays output for(elem <- s3) println(elem) } } Output: 4 5 Example #2: Scala // Scala program of diff() // method import scala.collection.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating SortedSets val s1 = SortedSet(1, 2, 3, 4, 5) val s2 = SortedSet(6, 2, 7, 8) // Applying diff method val s3 = s1.diff(s2) // Displays output for(elem <- s3) println(elem) } } Output: 1 3 4 5 Comment More infoAdvertise with us Next Article Scala SortedSet diff() method with example G gopaldave Follow Improve Article Tags : Scala Scala-Method scala-collection Similar Reads Scala SortedSet -() method with example The -() 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 // Scala program of -() // method import s 1 min read Scala SortedSet +() method with example The +() 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. Example #1: Scala // Scala 1 min read 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 diff() method with example 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 dif 2 min read Scala SortedSet drop() method with example The drop() method is utilized to delete the first ânâ elements or to return all elements except first 'n' elements. Method Definition: def drop(n: Int): SortedSet[A]] Return Type: It returns all elements except first 'n' elements. Example #1: Scala // Scala program of drop() // method import scala.c 1 min read Like