List of usage examples for java.util ArrayDeque removeFirstOccurrence
public boolean removeFirstOccurrence(Object o)
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);//w w w. j av a 2 s. c om deque.add(1); deque.add(25); deque.add(1); // this will remove first occurrence of element 1 deque.removeFirstOccurrence(1); System.out.println(deque); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveFirstOccurrence() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertFalse(deque.removeFirstOccurrence(o1)); deque.add(o1);//from w ww .j a v a 2s.c o m assertTrue(deque.removeFirstOccurrence(o1)); assertTrue(deque.isEmpty()); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3, o1, o2, o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3, o1, o3); assertTrue(deque.removeFirstOccurrence(o1)); checkDequeSizeAndContent(deque, o3, o1, o3); assertTrue(deque.removeFirstOccurrence(o1)); checkDequeSizeAndContent(deque, o3, o3); assertFalse(deque.removeFirstOccurrence(o1)); assertFalse(deque.removeFirstOccurrence(null)); }