Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ConcurrentLinkedQueue; public class JavaCollectionAddAllExample2 { public static void main(String[] args) { ConcurrentLinkedQueue
queue = new ConcurrentLinkedQueue
(); for (int i=0;i<=5;i++){ queue.add(i); } //will pass an error because both the collection can not be same queue.addAll(queue); System.out.println(queue); } }
Output