The java.util.concurrent.ConcurrentLinkedDeque.pollFirst() is an in-built method in Java which retrieves the first element of this deque and removes it. If the deque is empty, the method returns NULL.
Syntax:
Conn_Linked_Deque.pollFirst()
Parameters: This function does not accepts any parameter.
Return Values: The function returns the first element of this deque. If this deque is empty, the function returns NULL.
Below program illustrates the use of pollFirst() method:
Program 1: This program involves deque with Integer elements.
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<Integer> cld =
new ConcurrentLinkedDeque<Integer>();
cld.addFirst( 12 );
cld.addFirst( 70 );
cld.addFirst( 1009 );
cld.addFirst( 475 );
System.out.println( "Elements in"
+ "the LinkedDeque: " + cld);
System.out.println( "Element removed : "
+ cld.pollFirst());
System.out.println( "Elements in"
+ "the LinkedDeque: " + cld);
}
}
|
Output:
Elements inthe LinkedDeque: [475, 1009, 70, 12]
Element removed : 475
Elements inthe LinkedDeque: [1009, 70, 12]
Program 2: This program involves deque with String elements.
import java.util.concurrent.*;
class ConcurrentLinkedDequeDemo {
public static void main(String[] args)
{
ConcurrentLinkedDeque<String> cld =
new ConcurrentLinkedDeque<String>();
cld.addFirst( "GFG" );
cld.addFirst( "Geeks" );
cld.addFirst( "Gfg" );
cld.addFirst( "Geeks" );
System.out.println( "Elements in"
+ "the LinkedDeque: " + cld);
System.out.println( "Element removed : "
+ cld.pollFirst());
System.out.println( "Elements in"
+ "the LinkedDeque: " + cld);
}
}
|
Output:
Elements inthe LinkedDeque: [Geeks, Gfg, Geeks, GFG]
Element removed : Geeks
Elements inthe LinkedDeque: [Gfg, Geeks, GFG]
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#pollFirst()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 Nov, 2018
Like Article
Save Article