Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
java

What is Deque.remove() method in Java?

Sumit Sharma

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The Deque.remove() method is used to remove the head element from a deque. The Deque.remove() method is present in the Deque interface inside the java.util package.

Syntax

Deque.element remove()

Parameter

The Deque.remove() method doesn’t take any parameters.

Return

The Deque.remove() method returns the element present at the head of the deque, which is being removed.

Code

Let’s take a look at the code snippet below.

import java.util.*;
class Main
{
public static void main(String[] args)
{
Deque<Integer> d = new LinkedList<Integer>();
d.add(212);
d.add(23);
d.add(621);
d.add(1280);
d.add(3121);
d.add(18297);
d.add(791);
System.out.println("Elements of the deque are: " +d);
d.remove();
System.out.println("Elements in the deque are: "+d);
}
}
Using Deque.remove() method in Java

Explanation

  • In line 1, we imported the required package.
  • In line 2, we made a Main class.
  • In line 4, we made a main function.
  • In line 6, we declared a deque consisting of Integer type elements.
  • From lines 8-14, we inserted the elements in the deque by using the Deque.add() method.
  • In line 16, we displayed all the deque elements.
  • In line 18, we removed the head element from the deque by using the remove() method.
  • In line 20, we displayed the deque elements after removing the elements.

In this way, we can use Deque.remove() method in Java.

RELATED TAGS

communitycreator
java

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring