Java Collection Tutorial - Java Deque.addFirst(E e)








Syntax

Deque.addFirst(E e) has the following syntax.

void addFirst(E e)

Example

In the following code shows how to use Deque.addFirst(E e) method.

import java.util.ArrayDeque;
import java.util.Deque;
/* w ww. ja v  a 2s  . co  m*/
public class Main {
   public static void main(String[] args) {
      
      
      Deque<Integer>  deque = new ArrayDeque<Integer> (5);

      
      deque.add(25);
      deque.add(30);
      deque.add(35);

      deque.addFirst(10);
      deque.addFirst(15);
      deque.addFirst(20);

      deque.add(45);
      deque.add(40);

      System.out.println(deque);
   }
}

The code above generates the following result.