Online Java Compiler By
JavaTpoint.com
import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Predicate; public class JavaCollectionRemoveIfExample1 { public static void main(String[] args) { Collection
collection = new ConcurrentLinkedQueue
(); for (int i=1;i<21;i++){ collection.add(i);} System.out.println("Total no : "+ collection); //removes all the elements which satisfies the predicate filter Predicate
pr= a->(a%2!=0); //remove all the elements which do not come in 2's table collection.removeIf(pr ); System.out.println(" Table of 2 = "+collection); } }
Output