Java ArrayBlockingQueue clear() Method

The clear() method of ArrayBlockingQueue class automatically withdraws all the elements from this priority queue.

After calling this method, the queue will be empty.

Syntax:

Parameters:

NA

Specified By:

The clear() method of class ArrayBlockingQueue is specified by clear() method in interface Collection.

Override:

The clear() method of class ArrayBlockingQueue overrides the clear() method of class AbstractQueue.

Example 1

Output:

queue :
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

After applying clear operation:
queue : 
[]

Example 2

Output:

Name = [aman, bhavika]
After clearing the queue :
Name = []