This Java Example shows how to add an element at first and last position in java ArrayDeque object.
Add Element To First and Last Position Of Java ArrayDeque Example
This Java Example shows how to add an element at first and last
position in java ArrayDeque object. To add an element at first and last position
of Deque We use void addFirst(Object obj) And addLast(Object obj)
method. These method inserts the specified element at the First and last
position in the ArrayDeque respectively.
Example: AddFirstAndAddLastElementArrayDeque.java
package devmanuals.com; import java.util.*; public class AddFirstAndAddLastElementArrayDeque { public static void main(String args[]) { ArrayDeque ADeque = new ArrayDeque(); ADeque.add("A"); ADeque.add("B"); ADeque.add("C"); ADeque.add("D"); System.out.println("The ArrayDeque elements before addition are : " + ADeque); ADeque.addFirst("1"); ADeque.addLast("5"); System.out.println("The ArrayDeque elements after addition are : " + ADeque); } }
Output:
The ArrayDeque elements before addition are : [A, B, C, D]
The ArrayDeque elements after addition are : [1, A, B, C, D, 5] |
[ 0 ] Comments