Example usage for java.util ArrayDeque ArrayDeque

List of usage examples for java.util ArrayDeque ArrayDeque

Introduction

In this page you can find the example usage for java.util ArrayDeque ArrayDeque.

Prototype

public ArrayDeque(Collection<? extends E> c) 

Source Link

Document

Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(15);//from w  ww  .  j  ava2  s  . com
    deque.add(30);
    deque.add(20);
    deque.add(18);

    System.out.println(deque);

    int retval = deque.getFirst();
    System.out.println("Retrieved Element is = " + retval);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(25);/* w  w  w. ja va  2s  .  c  o  m*/
    deque.add(30);
    deque.add(20);
    deque.add(18);

    System.out.println(deque);

    // getLast() will retrieve element at last position
    int retval = deque.getLast();
    System.out.println("Retrieved Element is = " + retval);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//from w ww  . j  av a2 s  .  c  om
    deque.add(2);
    deque.add(3);
    deque.add(4);

    // this will remove element at the first(head) postion
    int retval = deque.remove();
    System.out.println("Element removed is: " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(25);//w  w  w .jav  a  2 s .  co  m
    deque.add(30);
    deque.add(20);
    deque.add(18);

    System.out.println(deque);
    int retval = deque.pollLast();
    System.out.println("Element removed is " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(15);//  w w w.j  av a  2 s  .  c  om
    deque.add(20);
    deque.add(25);
    deque.add(22);

    System.out.println(deque);

    // this will print the size of this deque
    int retval = deque.size();
    System.out.println("Size of deque = " + retval);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//  w  ww.  ja  v a2  s  . co m
    deque.add(2);
    deque.add(3);
    deque.add(3);

    System.out.println(deque);

    deque.removeLastOccurrence(3);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(15);//from ww w. j a va2  s . c o m
    deque.add(30);
    deque.add(25);
    deque.add(40);

    // this will remove element at the first(head) postion
    int retval = deque.removeFirst();
    System.out.println("Element removed is: " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);/*from   w w  w . ja v a  2  s.c  o m*/
    deque.add(2);
    deque.add(3);
    deque.add(4);

    System.out.println(deque);

    int retval = deque.pop();
    System.out.println("Element removed is " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//from   w ww  . ja  v  a2 s  .c  o m
    deque.add(2);
    deque.add(3);
    deque.add(4);

    System.out.println(deque);

    int retval = deque.poll();
    System.out.println("Element removed is " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(20);/*w  ww.  j av  a  2  s .  com*/
    deque.add(30);
    deque.add(20);
    deque.add(18);
    deque.add(22);
    deque.add(24);

    deque.addLast(10);
    deque.addLast(12);

    System.out.println(deque);
}