Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; public class ConcurrentLinkedQueueRetainAllExample1 { public static void main(String[] args) throws InterruptedException { List
list = new ArrayList
(); ConcurrentLinkedQueue
queue = new ConcurrentLinkedQueue
(); for (int i=1;i<21;i++){ queue.add(i); } System.out.println(" Elements in queue : " + queue); for (int i = 1; i < 11; i++) { int j = i *5; list.add(j); } //will give the elements int the queue which are present in list queue.retainAll(list); System.out.println(" Multiple of 5 : " + queue); } }
Output