Java Deque addFirst() MethodThe addFirst() method of Java Deque Interface is used to insert the specified element at the front of the deque . Syntax:Parameter:The above method consists of only one parameter:
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 1Test it NowOutput: The elements are adding at the front of the deque : [11, 22, 33, 44] Example 2Output: The subjects are given as : [DBMS, JAVA, CAO, FAT] Example 3Output: 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] Next TopicJava Deque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India