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

ParameterDescriptionRequired/Optional
dequeueDequeue 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

Test it Now

Output:

The resultant queue is: [Java, C, C++, Unix, Perl]

Example 2

Test it Now

Output:

The resultant view of the queue is: [1, 2, 3, 4, 5]

Example 3

Test it Now

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]





Latest Courses