The queue.clear
function in Scala is used to remove all the elements from a queue.
The illustration below shows a visual representation of the queue.clear
function.
The following module is required in order to use the function:
scala.collection.mutable.Queue
.
queue_name.clear
queue_name
is the name of the queue.
The queue.clear
function does not require any parameters.
Scala’s queue.clear
function does not return anything.
The following code shows how to use queue.clear
function in Scala.
import scala.collection.mutable.Queueobject Main extends App {var queue = Queue[Int]()queue.enqueue(1);queue.enqueue(3);queue.enqueue(5);queue.enqueue(2);queue.enqueue(0);//Queue = 1->3->5->2->0println("Following are the elements in Queue before clear: " + queue);queue.clear;println("Following are the elements in Queue after clear: " + queue);}