Example usage for java.util ArrayDeque add

List of usage examples for java.util ArrayDeque add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element at the end of this deque.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);
    deque.add(2);//from w ww .j  a va  2  s  .c  o  m
    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);
    deque1.add(2);// w  w w .  j a  v a2 s. c om
    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);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);
    deque.add(2);/*ww  w. j a  va2 s . c  om*/
    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);
    deque.add(18);/*from  www .  j ava2s  .  c  o m*/
    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);
    deque.add(2);//from www .j a  v  a 2  s.c  om
    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);
    deque.add(2);/*  w  ww  .  ja  v a  2s.co m*/
    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);
    deque.add(2);/*w  ww. j a  v  a 2 s. c  o m*/
    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);
    deque.add(2);//  ww w.  j  a  va 2  s. c om
    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) {

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

    deque.add(1);
    deque.add(2);//www  .  j ava2s .  c  om
    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);
    deque.add(2);//from  ww w .ja  v  a2 s. com
    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);
}