In Scala Stack class
, the isEmpty() is utilized to check if the stack is empty or not.
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the stack is empty or else it returns false.
Example #1:
// Scala program of isEmpty() // method // Import Stack import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating stack
val s 1 = Stack( 1 , 3 , 2 , 7 , 6 , 5 )
// Print the stack
println(s 1 )
// Applying isEmpty method
val result = s 1 .isEmpty
// Display output
print( "The stack is empty: " + result)
}
} |
Output:
Stack(1, 3, 2, 7, 6, 5) The stack is empty: false
Example #2:
// Scala program of isEmpty() // method // Import Stack import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating stack
val s 1 = Stack()
// Print the stack
println(s 1 )
// Applying isEmpty method
val result = s 1 .isEmpty
// Display output
print( "The stack is empty: " + result)
}
} |
Output:
Stack() The stack is empty: true