In Scala Stack class, the min() method is utilized to return the smallest element of the stack.
Method Definition: def min: A
Return Type: It returns the smallest element of the stack.
Example #1:
// Scala program of min() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(5, 3, 2, 7, 6, 1) // Print the stack println(s1) // Applying min method val result = s1.min // Display output print("The smallest element of the stack: " + result) } } |
chevron_right
filter_none
Output:
Stack(5, 3, 2, 7, 6, 1) The smallest element of the stack: 1
Example #2:
// Scala program of min() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(15, 13, 12, 7, 6, 11) // Print the stack println(s1) // Applying min method val result = s1.min // Display output print("The smallest element of the stack: " + result) } } |
chevron_right
filter_none
Output:
Stack(15, 13, 12, 7, 6, 11) The smallest element of the stack: 6
Recommended Posts:
- Scala Iterator min() method with example
- Scala Map min() method with example
- Scala List min() method with example
- Scala Set min() method with example
- Scala Float min() method with example
- Scala Queue min() method with example
- Scala Short min() method with example
- Scala SortedSet min() method with example
- Scala ListSet min() method with example
- Scala SortedMap min() method with example
- Scala Char min() method with example
- Scala TreeSet min() method with example
- Scala Int min() method with example
- Scala Mutable SortedMap min() 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
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.

