Javatpoint Logo
Javatpoint Logo

Java Deque remove() Method

The remove() method of Java Deque interface is used to retrieve and remove the head of the deque. The method may differ by poll() method only in one case that it throws an exception if the given deque is empty.

Specified by:

remove in interface Queue<E>

Syntax:

Parameter:

NA

Return:

The above method is used to return the head of the queue represented by the given deque.

Throw:

NoSuchElementException- If the given deque is empty.

Example 1

Test it Now

Output:

The first character which has been popped is : W
The remaining deque is given as :
E
L
C
O
M
E

Example 2

Test it Now

Output:

The first string that has been popped is : Computer
The remaining deque is given as : 
Programming
Language

Example 3

Test it Now

Output:

The first float value that has been popped is : 56.0
The remaining deque is given as : 
24.9
58.0

Java Deque remove() Method

The remove(Object o) method of Java Deque interface is used to remove the first occurrence of the given element from the deque. If the given deque has no element, then it remains unchanged. The above method returns true if the deque contains the specified element. Also, this method is equivalent to removeFirstOccurence(Object).

Specified by:

remove in interface Collection<E>

Syntax:

Parameter:

The above method requires only one parameter:

  1. The element 'o' that needs to be removed.

Return:

The above method is used to return true if the given element is removed.

Throw:

ClassCastException- If the class of the given element is incompatible with the given deque.

NullPointerException- If the specified element is already null and the given deque does not allow the null elements.

Example 1

Test it Now

Output:

The character is present in the deque : true
The remaining deque is given as :
W
E
L
C
O
E

Example 2

Test it Now

Output:

The float value is present in the deque : false
The remaining deque is given as :
76.0
89.9
60.8
45.1

Example 3

Test it Now

Output:

The long value is present in the deque : true
The remaining deque is given as :
67
50
22
Next TopicJava Deque





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA