ConcurrentLinkedDeque getFirst() method in Java Read Discuss Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report The java.util.concurrent.ConcurrentLinkedDeque.getFirst() method is an in-built method in Java which returns the first element of the deque container. Syntax: Conn_Linked_Deque.getFirst() Parameters: The method does not accept any parameter. Return Value: The method returns the first element present in the Deque. Exception: The function throws a NoSuchElementException when the deque is empty. Below programs illustrate the ConcurrentLinkedDeque.getFirst() method : Program 1: /* Java Program to Demonstrate getFirst() method of ConcurrentLinkedDeque */ import java.util.concurrent.*; class GFG { public static void main(String[] args) { // Creating an empty Deque ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>(); // Add elements into the Deque cld.add("Welcome"); cld.add("To"); cld.add("Geeks"); cld.add("4"); cld.add("Geeks"); // Displaying the Deque System.out.println("Elements in the Deque: " + cld); // Displaying the first element System.out.println("The first element is: " + cld.getFirst()); } } Output: Elements in the Deque: [Welcome, To, Geeks, 4, Geeks] The first element is: Welcome Program 2: /* Java Program to Demonstrate getFirst() method of ConcurrentLinkedDeque */ import java.util.concurrent.*; class GFG { public static void main(String[] args) { // Creating an empty Deque ConcurrentLinkedDeque<Integer> cld = new ConcurrentLinkedDeque<Integer>(); try { // Displaying the first element System.out.println("The first element " + "is: " + cld.getFirst()); } catch (Exception e) { System.out.println(e); } // Add elements into the Deque cld.add(12); cld.add(43); cld.add(29); cld.add(16); cld.add(70); // Displaying the Deque System.out.println("Elements in the Deque: " + cld); // Displaying the first element System.out.println("The first element is: " + cld.getFirst()); } } Output: java.util.NoSuchElementException Elements in the Deque: [12, 43, 29, 16, 70] The first element is: 12 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#getFirst() Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule. What We Offer: Comprehensive Course Expert Guidance for Efficient Learning Hands-on Experience with Real-world Projects Proven Track Record with 100,000+ Successful Geeks Last Updated : 17 Sep, 2018 Like Article Save Article Previous ConcurrentLinkedDeque offer() method in Java with Examples Next LinkedBlockingQueue toString() method in Java Please Login to comment...