Example usage for java.util ArrayDeque contains

List of usage examples for java.util ArrayDeque contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this deque contains the specified element.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(1);//from  w  w w  .j  ava2  s  . c o  m
    deque.add(2);
    deque.add(10);
    deque.add(18);

    System.out.println(deque);

    // deque contains element 10
    boolean retval = deque.contains(10);

    if (retval == true) {
        System.out.println("element 10 is contained in the deque");
    } else {
        System.out.println("element 10 is not contained in the deque");
    }

    // deque does not contain element 25
    boolean retval2 = deque.contains(25);

    if (retval2 == true) {
        System.out.println("element 25 is contained in the deque");
    } else {
        System.out.println("element 25 is not contained in the deque");
    }
}

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.contains(o3));
    assertFalse(deque.contains(null));//from w w w .ja  v  a2 s.  co  m
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o2));
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o3));
    assertTrue(deque.contains(o1));
    assertTrue(deque.contains(o2));
    assertTrue(deque.contains(o3));
    assertFalse(deque.contains(null));

    deque.clear();
    assertTrue(deque.isEmpty());
    assertFalse(deque.contains(o1));
    assertFalse(deque.contains(o2));
    assertFalse(deque.contains(o3));
}