Java Deque addFirst() Method
The addFirst() method of Java Deque Interface is used to insert the specified element at the front of the deque .
The above method consists of only one parameter:
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 1Test it Now
The elements are adding at the front of the deque : [11, 22, 33, 44]
The subjects are given as : [DBMS, JAVA, CAO, FAT]
Enter the number of times you want to enter the names : 4 The names are : Sham Ram Stuti Ranajna The final deque is : [Ranajna, Stuti, Ram, Sham]