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 program of equals() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stacks val s1 = Stack(1, 3, 2, 7, 6, 5) val s2 = Stack(1, 3, 2, 7, 6, 5) // Print the stack println("Stack_1: " + s1) println("Stack_2: " + s2) // Applying equals method val result = s1.equals(s2) // Display output println("Stack_1 == Stack_2: " + result) } } |
chevron_right
filter_none
Output:
Stack_1: Stack(1, 3, 2, 7, 6, 5) Stack_2: Stack(1, 3, 2, 7, 6, 5) Stack_1 == Stack_2: true
Example #2:
// Scala program of equals() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stacks val s1 = Stack(1, 3, 2, 7, 6, 5) val s2 = Stack(7, 3, 12, 7, 6, 5) // Print the stack println("Stack_1: " + s1) println("Stack_2: " + s2) // Applying equals method val result = s1.equals(s2) // Display output println("Stack_1 == Stack_2: " + result) } } |
chevron_right
filter_none
Output:
Stack_1: Stack(1, 3, 2, 7, 6, 5) Stack_2: Stack(7, 3, 12, 7, 6, 5) Stack_1 == Stack_2: false
Recommended Posts:
- Scala Set equals() method with example
- Scala Map equals() method with example
- Scala String equals() method with example
- Scala Queue equals() method with example
- Scala SortedSet equals() method with example
- Scala TreeSet equals() method with example
- Scala SortedMap equals() method with example
- Scala Int equals(arg0: Any) method with example
- Scala Mutable SortedMap equals() method with example
- Scala BitSet equals() method with example
- Scala Stack ++ method with example
- Scala Stack ++:() method with example
- Scala Stack +:() method with example
- Scala Stack :+() method with example
- Scala Stack /:() method with example
- Scala Stack :() method with example
- Scala Stack push() method with example
- Scala Stack pop() method with example
- Scala Stack pushAll() method with example
- Scala Stack contains() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

