ConcurrentLinkedDeque getLast() Method in Java Last Updated : 17 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.util.concurrent.ConcurrentLinkedDeque.getLast() method is an in-built method in Java which returns the last element of the deque container. Syntax: Conn_Linked_Deque.getLast() Parameters: The method does not accept any parameter. Return Value: The method returns the last element present in the Deque. Exception: The function throws a NoSuchElementException when the deque is empty. Below programs illustrate the ConcurrentLinkedDeque.getLast() method: Program 1: Java /* Java Program to Demonstrate getLast() 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 Deque: " + cld); // Displaying the Last element System.out.println("The Last element is: " + cld.getLast()); } } Output: Elements in Deque: [Welcome, To, Geeks, 4, Geeks] The Last element is: Geeks Program 2: Java /* Java Program to Demonstrate getLast() 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 Last element System.out.println("The Last element " + "is: " + cld.getLast()); } catch (Exception e) { // Displaying the Exception 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 " + "Deque: " + cld); // Displaying the Last element System.out.println("The Last element is: " + cld.getLast()); } } Output: java.util.NoSuchElementException Elements in Deque: [12, 43, 29, 16, 70] The Last element is: 70 Reference:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#getLast() Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque pollLast() method in Java R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ConcurrentLinkedDeque getFirst() method in Java 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 2 min read ConcurrentLinkedDeque element() method in Java The java.util.concurrent.ConcurrentLinkedDeque.element() is an in-built function in java which retrieves but does not remove the head of the queue represented by deque i.e the first element of deque.Syntax: conn_linked_deque.element() Parameter: This method has no parameters.Return Value: This metho 2 min read ConcurrentLinkedDeque addLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.addLast() is an in-built function in Java which inserts the specified element to the end of the deque. Syntax: conn_linked_deque.addLast(elem) Parameter: The method accepts only a single parameter elem which is to be added to the end of the ConcurrentLi 2 min read ConcurrentLinkedDeque peekLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.peekLast() is an in-built method in Java which retrieves the last element of this deque container without removing it. The function returns NULL if the deque is empty. Syntax: Conn_Linked_Deque.peekLast() Parameters: The function does not accepts any pa 2 min read ConcurrentLinkedDeque pollLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.pollLast() is an in-built method in Java which retrieves the last element of this deque and removes it. If the deque is empty, the method returns NULL. Syntax: Conn_Linked_Deque.pollLast() Parameters: The function accepts no parameters. Return Values:Th 2 min read ConcurrentLinkedDeque addFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.addFirst() is an in-built function in Java which inserts the specified element at the front of the ConcurrentLinkedDeque. Syntax: conn_linked_deque.addFirst(elem) Parameter: The method accepts only a single parameter elem which is to be added to the beg 2 min read Like