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(1);
    deque.add(2);/*from   w  w w.  java  2 s .c  o  m*/
    deque.add(3);
    deque.add(4);

    deque.offerFirst(10);

    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  va 2  s  . c  o m*/
    deque.add(3);
    deque.add(4);

    deque.offerLast(5);

    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);/*from  w w  w .ja v a2s  .com*/
    deque.add(3);
    deque.add(4);

    for (Iterator itr = deque.iterator(); itr.hasNext();) {
        System.out.println(itr.next());
    }
}

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 va 2  s.c o  m*/
    deque.add(3);
    deque.add(4);

    System.out.println(deque);

    int retval = deque.element();
    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 a2 s. c  o m*/
    deque.add(3);

    // adding elements using push() method
    deque.push(4);
    deque.push(5);

    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);//from ww  w.j a v  a 2 s.c  om
    deque.add(4);
    deque.add(5);

    int retval = deque.peekFirst();
    System.out.println("Retrieved Element 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);/*from   w w w . j av a 2s.  c om*/
    deque.add(3);
    deque.add(4);

    int retval = deque.peek();
    System.out.println("Retrieved Element 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);/* w w w .  ja  v  a  2s. c o m*/
    deque.add(25);
    deque.add(20);

    // this will remove first occurrence of element 20
    deque.removeFirstOccurrence(20);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(20);
    deque.add(30);/* www .  j  a  v  a 2 s . co  m*/
    deque.add(20);
    deque.add(30);
    deque.add(15);
    deque.add(22);
    deque.add(11);

    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);/* w w w  .  java 2s .c om*/
    deque.add(3);
    deque.add(4);

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

    System.out.println(deque);
}