Home » Java Deque removeLastOccurrence() Method with Examples

Java Deque removeLastOccurrence() Method with Examples

by Online Tutorials Library

Java Deque removeLastOccurrence() Method

The removeLastOccurrence() method of Deque interface is used to remove the last occurrence of the specified element from the given deque. If there is no element in the deque, then it remains unchanged. The above method returns true if the specified element is present in the deque.

Syntax:

Parameter:

The above requires only one parameter:

  1. The element ‘o’ that needs to be removed from the given deque.

Return:

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

Throw:

  • ClassCastException– If the specified 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 value is already present in the deque : true  The final deque is given as :   a  b  c  d  

Example 2

Test it Now

Output:

The value is already present in the deque : false  The final deque is given as :   23  45  63  45  

Example 3

Test it Now

Output:

The value is already present in the deque : true  The final deque is given as :   55.8  22.3  89.0  
Next TopicJava Deque

You may also like