85
Java ConcurrentLinkedQueue removeAll() Method
The removeAll() method of ConcurrentLinkedQueue class is used to remove the elements of the ConcurrentLinkedQueue that are matched with the items of the specified collection.
Syntax:
Parameters:
Here, the parameter c is the collection containing elements to be removed from ConcurrentLinkedQueue.
Specified By:
The removeAll () method of ConcurrentLinkedQueue class is specified by:
removeAll in interface Collection<E>.
Return Value:
The removeAll () method returns a Boolean value ‘true’ if the collection is changed otherwise it returns false.
Throws:
It throws NullPointerException if the specified collection does not support null elements or it contains one or more null elements.
Example 1
Output:
Queue : [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z] List of vowels : [A, E, I, O, U] Queue without vowels : [B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z]
Example 2
Output:
Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Even no : [2, 4, 6, 8, 10] Odd no : [1, 3, 5, 7, 9]
Example 3
Output:
Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920) at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:327) at java.util.concurrent.ConcurrentLinkedQueue.add(ConcurrentLinkedQueue.java:297) at com.tutorAspire.ConcurrentLinkedQueueRemoveAllExample3.main(ConcurrentLinkedQueueRemoveAllExample3.java:12)
Next TopicJava ConcurrentLinkedQueue