Home » Java Deque removeFirstOccurrence() Method with Examples

Java Deque removeFirstOccurrence() Method with Examples

by Online Tutorials Library

Java Deque removeFirstOccurrence() Method

The removeFirstOccurrence() method of Deque interface is used to remove the first occurrence of the given element from the deque. If there is no element in the deque, then it remains unchanged. It may return true if the deque contains the specified element.

Syntax:

Parameter:

The above requires only one parameter:

  1. The element ‘o’ that needs to remove d from the given deque.

Return:

The above method returns true if the particular element is removed from the deque.

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 already present? true  The final deque is given as :   a  b  d  

Example 2

Test it Now

Output:

The integer value is already preesnt? true  The final deque is given as :   7  6  2  

Example 3

Test it Now

Output:

The float value is already preesnt? false  The final deque is given as :   71.2  63.4  50.8  66.8  
Next TopicJava Deque

You may also like