LinkedBlockingDeque remove() method in Java
Last Updated :
17 Sep, 2018
The remove() method of LinkedBlockingDeque removes the head of the Deque container. The method throws a NoSuchElementException if the Deque container is empty.
Syntax:
public E remove()
Parameters: This method does not accepts any parameter.
Returns: This method does not returns anything.
Exception: The function throws a NoSuchElementException if the Deque is empty.
Below programs illustrate remove() method of LinkedBlockingDeque:
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.remove();
System.out.println( "Linked Blocking Deque: " + LBD);
}
}
|
Output:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
Linked Blocking Deque: [35658786, 5278367, 74381793]
Program 2:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws NoSuchElementException
{
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>( 6 );
LBD.add( 7855642 );
LBD.add( 35658786 );
LBD.add( 5278367 );
LBD.add( 74381793 );
System.out.println( "Linked Blocking Deque: " + LBD);
LBD.clear();
LBD.remove();
}
}
|
Output:
Exception in thread "main" java.util.NoSuchElementException
at java.util.concurrent.LinkedBlockingDeque.removeFirst(LinkedBlockingDeque.java:453)
at java.util.concurrent.LinkedBlockingDeque.remove(LinkedBlockingDeque.java:672)
at GFG.main(GFG.java:30)
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#remove–
Share your thoughts in the comments
Please Login to comment...