Scala Stack last() 方法与示例
在 Scala Stack class
中, isEmpty()用于检查堆栈是否为空。
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the stack is empty or else it returns false.
示例 #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 s1 = Stack(1, 3, 2, 7, 6, 5)
// Print the stack
println(s1)
// Applying isEmpty method
val result = s1.isEmpty
// Display output
print("The stack is empty: " + result)
}
}
输出:
Stack(1, 3, 2, 7, 6, 5)
The stack is empty: false
示例 #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 s1 = Stack()
// Print the stack
println(s1)
// Applying isEmpty method
val result = s1.isEmpty
// Display output
print("The stack is empty: " + result)
}
}
输出:
Stack()
The stack is empty: true