Scala Stack distinct() method with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala Stack class, the distinct() method is utilized to delete the duplicate elements from the given stack. Method Definition: def distinct: Stack[A] Return Type: It returns a new stack with only distinct elements. Example #1: Scala // Scala program of distinct() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(1, 3, 2, 1, 2, 1, 3, 2, 3, 3) // Print the stack println(s1) // Applying distinct() method val result = s1.distinct // Display output print("Stack with distinct elements: " + result) } } Output: Stack(1, 3, 2, 1, 2, 1, 3, 2, 3, 3) Stack with distinct elements: Stack(1, 3, 2) Example #2: Scala // Scala program of distinct() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack("g", "e", "e", "k", "s", "f", "o", "r", "g", "e", "e", "k", "s") // Print the stack println(s1) // Applying distinct() method val result = s1.distinct // Display output print("Stack with distinct elements: " + result) } } Output: Stack(g, e, e, k, s, f, o, r, g, e, e, k, s) Stack with distinct elements: Stack(g, e, k, s, f, o, r) Comment More infoAdvertise with us Next Article Scala Stack distinct() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads 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 Scala List distinct() method with example The distinct() method is utilized to delete the duplicate elements from the stated list. Method Definition: def distinct: List[A] Return Type: It returns a new list of elements without any duplicates. Example #1: Scala // Scala program of distinct() // method // Creating object object GfG { // Main 1 min read 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 Stack equals() method with example In Scala Stack class, the equals() method is utilized to check if two stacks consist of the same elements in the same order. Method Definition: def equals(o: Any): Boolean Return Type: It returns true if both the stacks are same or else returns false. Example #1: Scala // Scala program of equals() / 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 Like