Scala Queue isEmpty()方法及示例
isEmpty() 是用来检查队列是否为空的。
方法定义: def isEmpty:Boolean
返回类型。如果队列是空的,它返回真,否则返回假。
例子 #1:
// Scala program of isEmpty()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a queue
val q1 = Queue(1, 3, 2, 7, 6, 5)
// Print the queue
println(q1)
// Applying isEmpty method
val result = q1.isEmpty
// Display output
print("The queue is empty: " + result)
}
}
输出。
Queue(1, 3, 2, 7, 6, 5)
The queue is empty: false
例子#2。
// Scala program of isEmpty()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a queue
val q1 = Queue()
// Print the queue
println(q1)
// Applying isEmpty method
val result = q1.isEmpty
// Display output
print("The queue is empty: " + result)
}
}
输出。
Queue()
The queue is empty: true
极客教程