Scala Stack last() method with example
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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 1 , 3 , 2 , 7 , 6 , 5 )
println(s 1 )
val result = s 1 .isEmpty
print( "The stack is empty: " + result)
}
}
|
Output:
Stack(1, 3, 2, 7, 6, 5)
The stack is empty: false
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack()
println(s 1 )
val result = s 1 .isEmpty
print( "The stack is empty: " + result)
}
}
|
Output:
Stack()
The stack is empty: true
Last Updated :
03 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...