Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; public class JavaCollectionRemoveAllExample1 { public static void main(String[] args) { Collection
collection = new ConcurrentLinkedQueue
(); char i; for(i='1';i<='9';++i){ collection.add(i); } System.out.println("collection : "+collection); List
list = new ArrayList
(); list.add('2'); list.add('4'); list.add('6'); list.add('8'); System.out.println("List of even numbers : "+list); //removes all the elements in the collection which are present in list collection.removeAll(list); System.out.println("Odd numbers : "+collection); } }
Output