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.
Following is the declaration of asLifoQueue() method:
The asLifoQueue() method returns queue list as a result of the method call.
Java 1.6 and above
Example 1Test it Now
The resultant queue is: [Java, C, C++, Unix, Perl]
Example 2Test it Now
The resultant view of the queue is: [1, 2, 3, 4, 5]
Example 3Test it Now
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]