VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentlinkeddeque-offerfirst-method-in-java/

⇱ ConcurrentLinkedDeque offerFirst() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentLinkedDeque offerFirst() method in Java

Last Updated : 17 Sep, 2018
The java.util.concurrent.ConcurrentLinkedDeque.offerFirst() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, in the front of the deque. Syntax:
Conn_Linked_Deque.offerFirst(Object elem)
Parameters: The method accepts a parameter elem which species the element to be inserted to the front of the deque. Return Value: The function returns True if the element is successfully added into the deque and returns False otherwise. Exception: The function throws a NullPointerException if the passed parameter is NULL. Below programs illustrate the ConcurrentLinkedDeque.offerFirst() method: Program 1:
Output:
Elements in Deque: [Welcome, To, Geeks, 4, Geeks]
The First element is: Welcome
The Inserted element is: GFG
Elements in Deque: [GFG, Welcome, To, Geeks, 4, Geeks]
The First element is: GFG
Program 2:
Output:
Elements in Deque: [12, 43, 29, 16, 70]
The First element is: 12
java.lang.NullPointerException
The Inserted element is: 74
Elements in Deque: [74, 12, 43, 29, 16, 70]
The First element is: 74
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#offerFirst()
Comment