Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

queue
scala
communitycreator

What is queue.isEmpty in Scala?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The queue.isEmpty function in Scala is used to check if a queue is empty or not.

The illustration below shows the visual representation of the queue.isEmpty function.

Visual representation of queue.isEmpty function

The following module is required in order to use the function: scala.collection.mutable.Queue

Syntax


queue_name.isEmpty;
// where the queue_name is the name of the queue

Parameter

The queue.isEmpty function does not require any parameters.

Return value

If the queue is empty, the queue.isEmpty function returns true. Otherwise, it returns false.

Code

The following code shows how to use queue.isEmpty function in Scala.

import scala.collection.mutable.Queue
object Main extends App {
var queue = Queue[Int]()
queue.enqueue(1);
queue.enqueue(3);
queue.enqueue(5);
queue.enqueue(2);
queue.enqueue(0);
//filled queue
println("The Queue is empty: " + queue.isEmpty);
var queue_2 = Queue[Int]()
//empty queue
println("The Queue is empty: " + queue_2.isEmpty);
}

RELATED TAGS

queue
scala
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring