Scala Stack contains() method with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala Stack class, the contains() method is utilized to check if an element is present in the stack of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the stack or else it returns false. Example #1: Scala // Scala program of contains() // method import scala.collection.mutable.Stack // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a stack val s1 = Stack(1, 2, 3, 4, 5) // Print the stack println(s1) // Applying contains method val result = s1.contains(10) // Display output println("Stack contains element 10: " + result) } } Output: Stack(1, 2, 3, 4, 5) Stack contains element 10: false Example #2: Scala // Scala program of contains() // method import scala.collection.mutable.Stack // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a stack val s1 = Stack("C++", "Java", "Python", "Scala") // Print the stack println(s1) // Applying contains method val result = s1.contains("Scala") // Display output println("Stack contains element Scala: " + result) } } Output: Stack(C++, Java, Python, Scala) Stack contains element Scala: true Comment More infoAdvertise with us Next Article Scala Stack contains() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set contains() method with example The contains() method is utilized to check if an element is present in the set of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the set else it returns false. Example #1: Scala // Scala program of contains() // method // Creating obj 1 min read Scala TreeSet contains() method with example In Scala TreeSet class, the contains() method is utilized to check if an element is present in the TreeSet of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the TreeSet or else it returns false. Example #1: Scala // Scala program of c 1 min read Scala SortedMap contains() method with example The contains() method of Scala is equivalent to the isDefinedAt method of Scala but the only difference is that isDefinedAt is observed on all the PartialFunction classes while contains is clearly defined to the SortedMap interface of Scala. It checks whether the stated SortedMap contains a binding 2 min read Scala SortedSet contains() method with example The contains() method is utilized to check if an element is present in the SortedSet of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the SortedSet else it returns false. Example #1: Scala // Scala program of contains() // method imp 1 min read Scala Set count() method with example The count() method is utilized to count the number of elements in the set. Method Definition: def count(p: (A) => Boolean): Int Return Type: It returns the number of elements present in the set. Example #1: Scala // Scala program of count() // method // Creating object object GfG { // Main method 1 min read Like