Example usage for java.util ArrayDeque remove

List of usage examples for java.util ArrayDeque remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes a single instance of the specified element from this deque.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);//from w w  w  .j av a 2 s .com
    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);
}

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

public void testRemoveElement() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.remove(o1));

    deque.add(o1);/*  ww  w. j ava2 s .c o  m*/
    assertTrue(deque.remove(o1));
    assertTrue(deque.isEmpty());

    deque.add(o1);
    deque.add(o2);
    assertTrue(deque.remove(o1));
    checkDequeSizeAndContent(deque, o2);
    assertTrue(deque.remove(o2));
    assertTrue(deque.isEmpty());

    assertFalse(deque.remove(null));
}