RemoveFirstOccurrence() Method : ArrayDeque in Java
Declaration :
1 |
public boolean removeFirstOccurrence(Object o) |
Explanation :
Purpose | The java.util.ArrayDeque.removeFirstOccurrence(Object) method removes the first occurrence of the specified element in this deque. |
Parameters | o ===> The element whose first occurrence is to be removed from this deque if present. |
Return Value | This method returns true if the deque contains the specified element. |
Exception | NA |
Java Program : Example
Below example will explain java.util.ArrayDeque.removeFirstOccurrence(o) method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package com.c4learn; import java.util.ArrayDeque; import java.util.Deque; public class ArrayDequeDemo { public static void main(String[] args) { // Create empty array deque with an initial capacity Deque<Integer> deque = new ArrayDeque<Integer>(8); // Use add() method to add elements deque.add(100); deque.add(200); deque.add(100); deque.add(400); deque.add(100); System.out.println("Deque before : " + deque); // Remove elements using removeFirstOccurrence() deque.removeFirstOccurrence(100); System.out.println("Deque after : " + deque); } } |
Output of Program :
1 2 |
Deque before : [100, 200, 100, 400, 100] Deque after : [200, 100, 400, 100] |