Example usage for java.util ArrayDeque peekFirst

List of usage examples for java.util ArrayDeque peekFirst

Introduction

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

Prototype

public E peekFirst() 

Source Link

Usage

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

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

    System.out.println(deque);
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testPeekFirst() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.peekFirst());

    deque.add(o1);//from w  ww. ja  va 2 s .  c o m
    assertEquals(o1, deque.peekFirst());
    checkDequeSizeAndContent(deque, o1);

    deque.add(o2);
    assertEquals(o1, deque.peekFirst());
    checkDequeSizeAndContent(deque, o1, o2);

    deque.addFirst(o3);
    assertEquals(o3, deque.peekFirst());
    checkDequeSizeAndContent(deque, o3, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    assertNull(deque.peekFirst());
}