79
Java Collections asLifoQueue() Method
The asLifoQueue() is an inbuilt method of Java Collections class which returns a view of a Deque as a Last-in-first-out (LIFO) Queue. In this method, the method add and remove is mapped to push and pop operation respectively. It is useful when we want to use a method requiring a Queue but we need LIFO order.
Syntax
Following is the declaration of asLifoQueue() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
dequeue | Dequeue the provided collection List. | Required |
Returns
The asLifoQueue() method returns queue list as a result of the method call.
Exceptions
NA
Compatibility Version
Java 1.6 and above
Example 1
Output:
The resultant queue is: [Java, C, C++, Unix, Perl]
Example 2
Output:
The resultant view of the queue is: [1, 2, 3, 4, 5]
Example 3
Output:
Initial view of the queue is: [1, 2] New queue value is: [1, 2, 3] The resultant view of the queue is: [5, 4, 1, 2, 3]
Next TopicJava Collections Class