Scala Queue clear() method with example
The clear() method is utilized to delete all the elements of the queue.
Method Definition: def clear(): Unit
Return Type: It returns an empty queue.
Example #1:
// Scala program of clear() // method // Import Queue import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a queue val q 1 = Queue( 10 , 11 , 12 , 13 , 14 ) // Print the queue println( "Before clear() method: " + q 1 ) // Applying clear() method q 1 .clear() // Display output print( "After clear() method: " + q 1 ) } } |
chevron_right
filter_none
Output:
Before clear() method: Queue(10, 11, 12, 13, 14) After clear() method: Queue()
Example #2:
// Scala program of clear() // method // Import Queue import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a queue val q 1 = Queue( "geeks" , "for" , "geeks" ) // Print the queue println( "Before clear() method: " + q 1 ) // Applying clear() method q 1 .clear() // Display output print( "After clear() method: " + q 1 ) } } |
chevron_right
filter_none
Output:
Before clear() method: Queue(geeks, for, geeks) After clear() method: Queue()