Example usage for java.util Deque add

List of usage examples for java.util Deque add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(15);
    deque.add(30);//from   www .j  a  v  a 2 s . c o  m
    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);
    deque.add(30);//w  w w . ja v a 2s. c  o  m
    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);
    deque.add(2);/*from w ww  . j  av a  2  s  .  c o  m*/
    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);
    deque.add(30);/*from   ww w .  j a  v  a2s.c o m*/
    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);
    deque.add(20);/*from  w w w .  j ava  2s . co m*/
    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);
    deque.add(2);/*  www .  j a  va  2  s  .  com*/
    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);
    deque.add(30);//from   www.  ja  va 2  s. c  o m
    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);
    deque.add(2);//ww w . ja  v  a  2s  .  c  o m
    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);
    deque.add(2);//ww w. j a  v a 2s . c  o m
    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>(7);

    deque.add(1);
    deque.add(2);//from w w w .  ja v  a 2 s  .com
    deque.add(3);
    deque.add(4);
    deque.add(5);

    // get queue from the deque
    Queue<Integer> nq = Collections.asLifoQueue(deque);

    System.out.println("View of the queue is: " + nq);
}