带有示例的 Scala Queue isEmpty() 方法
isEmpty()用于检查队列是否为空。
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the queue is empty or else it returns false.
示例 #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