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  www. j  av  a 2s.  co  m*/
    deque.add(2);
    deque.add(1);
    deque.add(18);

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

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

    deque.add(3);//from  ww  w .  ja  v  a2 s.  c  o m
    deque.add(18);
    deque.add(25);
    deque.add(18);

    System.out.println(deque);

    deque.removeLastOccurrence(18);

    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 ww .  j  av a2  s.c om
    deque.add(2);
    deque.add(1);
    deque.add(18);

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

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

    deque.add(1);//  w  w  w  .  j a  va 2  s  .  co  m
    deque.add(2);
    deque.add(1);
    deque.add(18);
    deque.add(4);
    deque.add(24);

    // the values will be printed in the same order
    deque.addLast(10);
    deque.addLast(12);

    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);//from w  ww.  j  a va 2 s  .co m
    deque.add(2);
    deque.add(25);
    deque.add(40);

    System.out.println(deque);

    // this will remove element at last position
    int retval = deque.removeLast();
    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>(5);

    deque.add(25);//from   ww w.  ja  va 2s.c  om
    deque.add(2);
    deque.add(35);

    deque.addFirst(10);
    deque.addFirst(3);
    deque.addFirst(1);//now, element 1 will be at the front

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

    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);//from   w w  w.  j a va  2  s. c om
    deque.add(30);
    deque.add(10);
    deque.add(18);

    System.out.println(deque);

    // deque contains element 10
    boolean retval = deque.contains(10);

    if (retval == true) {
        System.out.println("element 10 is contained in the deque");
    } else {
        System.out.println("element 10 is not contained in the deque");
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);//from w w  w.  j a va 2  s  . co  m
    deque.add(30);
    deque.add(20);
    deque.add(40);

    System.out.println(deque);

    boolean retval = deque.remove(30);
    if (retval == true) {
        System.out.println("element 30 is removed from the deque");
    } else {
        System.out.println("element 30 is not contained in the deque");
    }

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(1);/* w  w  w.j  av a2s . co  m*/
    deque.add(2);
    deque.add(10);

    System.out.println(deque);

    // finding size of this deque
    int retval = deque.size();
    System.out.println("Deque consists of " + retval + " elements");

    deque.clear();
    retval = deque.size();
    System.out.println("Now, deque consists of " + retval + " elements");
}

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 a  v a2 s  .  c  om
    deque.add(2);
    deque.add(1);
    deque.add(40);

    System.out.println(deque);

    // deque contains element 2, returns true
    boolean retval = deque.remove(2);
    if (retval == true) {
        System.out.println("element 2 is removed from the deque");
    } else {
        System.out.println("element 2 is not contained in the deque");
    }
    System.out.println(deque);
}