VOOZH about

URL: https://www.geeksforgeeks.org/java/arraydeque-remove-method-in-java/

⇱ ArrayDeque remove() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ArrayDeque remove() Method in Java

Last Updated : 10 Dec, 2018
  1. The Java.util.ArrayDeque.remove() method is used to remove the element present at the head of the Deque. Syntax:
    Array_Deque.remove()
    Parameters: The method does not take any parameters. Return Value: This method returns the element present at the head of the Deque. Exceptions: The method throws NoSuchElementException is thrown if the deque is empty. Below programs illustrate the Java.util.ArrayDeque.remove() method: Program 1:
    Output:
    Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks]
    ArrayDeque after removing elements: [Geeks, For, Geeks]
    
    Program 2:
    Output:
    Initial ArrayDeque: [10, 15, 30, 20, 5]
    ArrayDeque after removing elements: [30, 20, 5]
    
  2. The Java.util.ArrayDeque.remove(Object) method is used to remove a particular element from an ArrayDeque. Syntax:
    Priority_Queue.remove(Object O)
    Parameters: The parameter O is of the type of ArrayDeque and specifies the element to be removed from the ArrayDeque. Return Value: This method returns True if the specified element is present in the Deque else it returns False. Below programs illustrate the Java.util.ArrayDeque.remove() method: Program 1:
    Output:
    Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks]
    ArrayDeque after removing elements: [To, Geeks]
    
    Program 2:
Output:
Initial ArrayDeque: [10, 15, 30, 20, 5]
ArrayDeque after removing elements: [10, 15, 20]
Comment