GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — ArrayDeque remove() Method in Java - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

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: Java
    // Java code to illustrate remove()
    import java.util.*;
    
    public class ArrayDequeDemo {
        public static void main(String args[])
        {
            // Creating an empty ArrayDeque
            Deque<String> de_que = new ArrayDeque<String>();
    
            // Use add() method to add elements into the Deque
            de_que.add("Welcome");
            de_que.add("To");
            de_que.add("Geeks");
            de_que.add("For");
            de_que.add("Geeks");
    
            // Displaying the ArrayDeque
            System.out.println("Initial ArrayDeque: " + de_que);
    
            // Removing elements using remove() method
            de_que.remove();
            de_que.remove();
    
            // Displaying the ArrayDeque after removal
            System.out.println("ArrayDeque after removing "
                               + "elements: " + de_que);
        }
    }
    
    Output:
    Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks]
    ArrayDeque after removing elements: [Geeks, For, Geeks]
    
    Program 2: Java
    // Java code to illustrate remove()
    import java.util.*;
    
    public class ArrayDequeDemo {
        public static void main(String args[])
        {
            // Creating an empty ArrayDeque
            Deque<Integer> de_que = new ArrayDeque<Integer>();
    
            // Use add() method to add elements into the Deque
            de_que.add(10);
            de_que.add(15);
            de_que.add(30);
            de_que.add(20);
            de_que.add(5);
    
            // Displaying the ArrayDeque
            System.out.println("Initial ArrayDeque: " + de_que);
    
            // Removing elements using remove() method
            de_que.remove();
            de_que.remove();
    
            // Displaying the ArrayDeque after removal
            System.out.println("ArrayDeque after removing "
                               + "elements: " + de_que);
        }
    }
    
    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: Java
    // Java code to illustrate remove()
    import java.util.*;
    
    public class ArrayDequeDemo {
        public static void main(String args[])
        {
            // Creating an empty ArrayDeque
            Deque<String> de_que = new ArrayDeque<String>();
    
            // Use add() method to add elements into the Deque
            de_que.add("Welcome");
            de_que.add("To");
            de_que.add("Geeks");
            de_que.add("For");
            de_que.add("Geeks");
    
            // Displaying the ArrayDeque
            System.out.println("Initial ArrayDeque: " + de_que);
    
            // Removing elements using remove() method
            de_que.remove("Geeks");
            de_que.remove("For");
            de_que.remove("Welcome");
    
            // Displaying the ArrayDeque after removal
            System.out.println("ArrayDeque after removing "
                               + "elements: " + de_que);
        }
    }
    
    Output:
    Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks]
    ArrayDeque after removing elements: [To, Geeks]
    
    Program 2: Java
    // Java code to illustrate remove()
    import java.util.*;
    
    public class ArrayDequeDemo {
        public static void main(String args[])
        {
            // Creating an empty ArrayDeque
            Deque<Integer> de_que = new ArrayDeque<Integer>();
    
            // Use add() method to add elements into the Deque
            de_que.add(10);
            de_que.add(15);
            de_que.add(30);
            de_que.add(20);
            de_que.add(5);
    
            // Displaying the ArrayDeque
            System.out.println("Initial ArrayDeque: " + de_que);
    
            // Removing elements using remove() method
            de_que.remove(30);
            de_que.remove(5);
    
            // Displaying the ArrayDeque after removal
            System.out.println("ArrayDeque after removing "
                               + "elements: " + de_que);
        }
    }
    
Output:
Initial ArrayDeque: [10, 15, 30, 20, 5]
ArrayDeque after removing elements: [10, 15, 20]
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.