Retains
only the elements in this collection that are contained in the specified collection. In other
words, removes from this collection all of its elements that are not contained in the specified collection.

package com.logicbig.example.arrayblockingqueue;
import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
public class RetainAllExample {
public static void main(String... args) {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(3, true, Arrays.asList(1, 3, 5));
System.out.println("queue before: " + q);
boolean b = q.retainAll(Arrays.asList(1, 5, 7));
System.out.println(b);
System.out.println("queue after: " + q);
}
}
Output
queue before: [1, 3, 5]
true
queue after: [1, 5]