addLast()
Java Deque addLast() Method
Last Updated : 17 Mar 2025
The addLast() method of Java Deque Interface is used to insert the specified element at the end of the deque.
Syntax:
Parameter:
The above method consists of only one parameter:
- The element 'e' that needs to be inserted.
Return:
NA
Throw:
IllegalStateException- If the elements cannot be added at the time due to capacity restriction.
ClassCastException- If the class of the specified element avoids it from being added to the deque.
NullPointerException- If the specified element is a null and the deque does not allow the null elements.
IllegalArgumentException- If some of the property of the given element avoids it from being added to the deque.
Example 1
Output:
The elements are adding at the front of the deque : [44, 33, 22, 11]
Example 2
Output:
The subjects are given as : [FAT, CAO, JAVA, DBMS]
Example 3
Output:
Enter the number of times you want to enter the names : 4 The names are : Ashu Hitesh Jasmeet Isha The final deque is : [Ashu, Hitesh, Jasmeet, Isha]