The asLifoQueue() method of java.util.Collections class is used to return a view of a Deque as a Last-in-first-out (Lifo) Queue. Method add is mapped to push, remove is mapped to pop and so on. This view can be useful when you would like to use a method requiring a Queue but you need Lifo ordering.
Each method invocation on the queue returned by this method results in exactly one method invocation on the backing deque, with one exception. The addAll method is implemented as a sequence of addFirst invocations on the backing deque.
public static Queue asLifoQueue(Deque deque)
Parameters: This method takes deque as a parameter which is to be converted into a LifoQueue.
Return Value: This method returns a LifoQueue from the deque.
Below are the examples to illustrate the asLifoQueue() method
View of the queue is: [1, 2, 3, 4, 5]
View of the queue is: [Ram, Gopal, Verma]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.