Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Predicate; public class ConcurrentLinkedQueueRemoveIfExample2 { public static void main(String[] args) { ConcurrentLinkedQueue
queue = new ConcurrentLinkedQueue
(); IsVoter isVoter1 = new IsVoter("Reema",18); IsVoter isVoter2 = new IsVoter("Raj",7); IsVoter isVoter3 = new IsVoter("Kajol",37); IsVoter isVoter4 = new IsVoter("Ravi",47); IsVoter isVoter5 = new IsVoter("Varun",17); queue.add(isVoter1); queue.add(isVoter2); queue.add(isVoter3); queue.add(isVoter4); queue.add(isVoter5); //removes all the elements which satisfies the Predicate filter Predicate
pr= (IsVoter age) ->(age.age < 18); queue.removeIf(pr ); System.out.println(" People eligible to vote : "); for (IsVoter xyz : queue ){ System.out.println(xyz); } } } class IsVoter { String name; int age; public IsVoter(String name, int age) { this.name = name; this.age = age; } public String toString() { return "Name = " + this.name + " Age = " + this.age; } }
Output