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) {

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

    deque.add(25);/*from ww  w  .  j av  a 2  s.c om*/
    deque.add(2);
    deque.add(1);
    deque.add(18);

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

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);// w w  w  .j  av  a  2s.c  om
    deque.add(2);
    deque.add(1);
    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) {

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

    deque.add(3);//from  w  w w .  j  ava 2  s .  com
    deque.add(1);
    deque.add(25);
    deque.add(18);

    System.out.println(deque);

    // printing the array length of elements added above
    Object[] ob = deque.toArray();
    System.out.println("\n Array Size : " + ob.length);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(3);//w w w.j  av a2  s .  c  o m
    deque.add(2);
    deque.add(1);
    deque.add(18);

    System.out.println(deque);

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

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);//from w ww .  j av  a2 s  .co  m
    deque.add(2);
    deque.add(1);
    deque.add(18);

    // this will retrieve end value
    int retval = deque.peekLast();
    System.out.println("Retrieved Element is " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);/*from  www  . ja  v  a  2 s  .c  o  m*/
    deque.add(2);
    deque.add(1);
    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) {

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

    deque.add(3);/*  w w  w .j av a  2s.co  m*/
    deque.add(1);
    deque.add(25);
    deque.add(4);

    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) {

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

    deque.add(3);//from w w w  . j  a v a2s. com
    deque.add(1);
    deque.add(25);
    deque.add(18);

    System.out.println(deque);

    // printing the array length of elements added above
    Integer[] ob = deque.toArray(new Integer[deque.size()]);
    System.out.println("\n Array Size : " + ob.length);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);//from   ww  w. jav a 2  s  . com
    deque.add(2);
    deque.add(1);
    deque.add(40);

    // 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) {

    ArrayDeque<Integer> deque1 = new ArrayDeque<Integer>(8);

    deque1.add(3);// w w w  .j a  va  2s .  c  o m
    deque1.add(2);
    deque1.add(1);
    deque1.add(18);

    // clone the first deque,
    Deque<Integer> deque2 = deque1.clone();

    // print all the elements available in deque2
    System.out.println(deque2);
}