Java ConcurrentLinkedQueue ClassConcurrentLinkedQueue is an unbounded thread-safe queue which arranges the element in FIFO. New elements are added at the tail of this queue and the elements are added from the head of this queue. ConcurrentLinkedQueue class and its iterator implements all the optional methods of the Queue and Iterator interfaces. MethodsMethods | Description |
---|
add() | Inserts the specified element at the tail of this queue | addAll() | Inserts all the elements which are present in the specified collection to the tail of this queue | contains() | Returns true if this queue contains the specified element | forEach() | Performs the given action for each element until all elements have been processed. | isEmpty() | Returns true if this queue contains no elements. | iterator() | Returns an iterator over the elements in this queue | offer() | Inserts the specified element at the tail of this queue | remove() | Removes the specified element from this queue, if this element is present in the queue | removeAll() | Removes all the elements of this in queue which are present in the specified collection. | removeIf() | Removes all the elements in this queue that satisfy the given predicate filter. | retainAll() | Retain only those elements in this queue that are present in the specified collection. | size() | Returns the number of the elements in this queue. | spliterator() | Returns a spliterator over the elements in this queue. | toArray() | Returns an array containing all the elements of this queue which are in proper sequence. |
Example 1Test it NowOutput: Queue : [1, 2, 3, 4, 5, 6]
This queue conatins 4
Queue is not empty
Example 2Test it NowOutput: Elements in queue : [11, 100, 122, 102, 112]
Remaining elements in queue : [11, 100, 112]
Elemts of the list will get removed : [112]
Queue will retain the elements of the list: []
|