The Wayback Machine - https://web.archive.org/web/20240618020153/https://www.geeksforgeeks.org/arraydeque-addlast-method-in-java/
Open In App

ArrayDeque addLast() Method in Java

Last Updated : 20 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The java.util.ArrayDeque.addLast(Object element) method in Java is used to insert a specific element at the end of this deque. It is similar to the add() method in Java. Syntax:

Array_Deque.addLast(Object element)

Parameters: The parameter element is of the type ArrayDeque and refers to the element to be added. Return Value: The function does not return any value. Exceptions: The method throws NullPointerException if the passed parameter is NULL. 

The Time Complexity of this addLast(Object element) is O(1) i.e Constant.

Below programs illustrate the Java.util.ArrayDeque.addLast() method: 

Program 1: Adding Integers to the Deque. 

Java




// Java code to illustrate addLast()
import java.util.*;
   
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        Deque<Integer> de_que = new ArrayDeque<Integer>();
   
        // Use add() method to add elements into the Deque
        de_que.add(10);
        de_que.add(15);
        de_que.add(30);
        de_que.add(20);
        de_que.add(5);
   
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
   
        // Adding elements at the end
        de_que.addLast(40);
        de_que.addLast(50);
        de_que.addLast(60);
        de_que.addLast(70);
   
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque_end_addition: " + de_que);
    }
}


Output:

ArrayDeque: [10, 15, 30, 20, 5]
ArrayDeque_end_addition: [10, 15, 30, 20, 5, 40, 50, 60, 70]

Program 2: Adding String to the Deque. 

Java




// Java code to illustrate addLast()
import java.util.*;
   
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        Deque<String> de_que = new ArrayDeque<String>();
   
        // Use add() method to add elements into the Deque
        de_que.add("Welcome");
        de_que.add("To");
        de_que.add("Geeks");
        de_que.add("4");
        de_que.add("Geeks");
   
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
   
        // Adding elements at end
        de_que.addLast("GFG");
        de_que.addLast("World");
        de_que.addLast("Hello");
   
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque_end_addition: " + de_que);
    }
}


Output:

ArrayDeque: [Welcome, To, Geeks, 4, Geeks]
ArrayDeque_end_addition: [Welcome, To, Geeks, 4, Geeks, GFG, World, Hello]


Previous Article
Next Article

Similar Reads

LinkedList addLast() Method in Java
The java.util.LinkedList.addLast() method in Java is used to insert a specific element at the end of a LinkedList.Syntax: void addLast(Object element) Parameters: This function accepts a single parameter element as shown in the above syntax. The element specified by this parameter is appended at end of the list.Return Value: This method does not re
1 min read
LinkedBlockingDeque addLast() method in Java
The addLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter to the end of the Deque if there is space. If the LinkedBlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax: public void addLast(E e) Parameters: This method accepts a mandatory parameter e whic
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 ConcurrentLinkedDeque. Return Value: The function has no retur
2 min read
Deque addLast() method in Java
The addLast(E e) method of Deque Interface inserts the element passed in the parameter to the end of the Deque if there is space. If the Deque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax: boolean addLast(E e) Parameters: This method accepts
4 min read
BlockingDeque addLast() method in Java with Examples
The addLast(E e) method of BlockingDeque inserts the element passed in the parameter to the end of the Deque if there is space. If the BlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax: public void addLast(E e) Parameters: This method accepts a mandatory parameter e which is the ele
2 min read
Java 8 | ArrayDeque removeIf() method in Java with Examples
The removeIf() method of ArrayDeque is used to remove all those elements from ArrayDeque which satisfies a given predicate filter condition passed as a parameter to the method. This method returns true if some element are removed from the Vector. Java 8 has an important in-built functional interface which is Predicate. Predicate, or a condition che
3 min read
Java.util.ArrayDeque Class in Java | Set 1
java.util.ArrayDeque class describes an implementation of a resizable array structure which implements the Deque interface. Array deques has not immutable and can grow as necessary. They are not thread-safe and hence concurrent access by multiple threads is not supported unless explicitly synchronized. Null elements are invalid in this structure. M
5 min read
Java.util.ArrayDeque Class in Java | Set 2
Java.util.ArrayDeque Class in Java | Set 1 More Methods of util.ArrayDeque Class : 16. offer(Element e) : java.util.ArrayDeque.offer(Element e) : inserts element at the end of deque. Syntax : public boolean offer(Element e) Parameters : e - element to add Return : true, if element is added else; false 17. offerFirst(Element e) : java.util.ArrayDequ
5 min read
ArrayDeque offerLast() Method in Java
The Java.util.ArrayDeque.offerLast(Object element) method in Java is used to add a specific element at the end of this Deque. The function is similar to the addLast(), add() and offer() method of ArrayDeque in Java. Syntax: Array_Deque.offerLast(Object element) Parameters: The parameter element is of the type ArrayDeque and refers to the element to
2 min read
ArrayDeque toArray() Method in Java
The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: The method returns an array containing the elements
2 min read