Scala Queue diff() method with example Last Updated : 23 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The diff() method is used to find the difference between the two queues. It deletes elements that are present in one queue from the other one. Method Definition: def diff[B >: A](that: collection.Seq[B]): Queue[A] Return Type: It returns a new queue which consists of elements after the difference between the two queues. Example #1: Scala // Scala program of diff() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating queues val q1 = Queue(1, 2, 3, 4, 5) val q2 = Queue(3, 4, 5) // Print the queue println("Queue_1: " + q1) println("Queue_2: " + q2) // Applying diff method val result = q1.diff(q2) // Displays output print("(Queue_1 - Queue_2): " + result) } } Output: Queue_1: Queue(1, 2, 3, 4, 5) Queue_2: Queue(3, 4, 5) (Queue_1 - Queue_2): Queue(1, 2) Example #2: Scala // Scala program of diff() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating queues val q1 = Queue(1, 2, 3, 4, 5) val q2 = Queue(3, 4, 5, 6, 7, 8) // Print the queue println("Queue_1: " + q1) println("Queue_2: " + q2) // Applying diff method val result = q2.diff(q1) // Displays output print("(Queue_2 - Queue_1): " + result) } } Output: Queue_1: Queue(1, 2, 3, 4, 5) Queue_2: Queue(3, 4, 5, 6, 7, 8) (Queue_2 - Queue_1): Queue(6, 7, 8) Comment More infoAdvertise with us Next Article Scala Queue diff() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Queue distinct() method with example The distinct() method is utilized to remove the duplicate elements from the given queue. Method Definition: def distinct: Queue[A] Return Type: It returns a new queue that contains only distinct elements. Example #1: Scala // Scala program of distinct() // method // Import Queue import scala.collect 2 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 Queue equals() method with example The equals() method is utilized to check if two queues consists of the same elements in the same order. Method Definition: def equals(o: Any): Boolean Return Type: It returns true if both the queues are same or else returns false. Example #1: Scala // Scala program of equals() // method // Import Qu 2 min read Scala Queue find() method with example The find() method is utilized to return an element that satisfy a given predicate in the queue. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element that satisfies a given predicate if present or else it returns None. Example #1: Scala // Scala progr 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