LinkedBlockingDeque removeIf() method in Java with Examples
Last Updated :
26 Mar, 2019
The removeIf() method of LinkedBlockingDeque removes the element from this LinkedBlockingDeque that satisfies the specified condition.
Syntax:
public boolean removeIf (Predicate<? super E> filter)
Parameters: This method accepts a mandatory parameter filter which is the predicate value based on which elements are removed from this Deque.
Returns: This method returns a boolean value such as true, if the LinkedBlockingDeque is changed. Else this method returns false.
Exceptions: This method throws NullPointerException if the specified Predicate filter is null.
Below program illustrates the removeIf() function of LinkedBlockingDeque class :
Program 1:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
LBD.add( 7855642 );
LBD.add( 35658786 );
LBD.add( 5278367 );
LBD.add( 74381793 );
System.out.println( "Linked Blocking Deque: "
+ LBD);
LBD.removeIf(number -> number % 3 == 0 );
System.out.println( "Linked Blocking Deque: "
+ LBD);
}
}
|
Output:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
Linked Blocking Deque: [7855642, 5278367]
Program 2:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
LBD.add( 7855642 );
LBD.add( 35658786 );
LBD.add( 5278367 );
LBD.add( 74381793 );
System.out.println( "Linked Blocking Deque: "
+ LBD);
try {
LBD.removeIf( null );
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
java.lang.NullPointerException
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedBlockingDeque.html#removeIf-java.util.function.Predicate-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...