Home »
Java programming language
Java Collections asLifoQueue() Method with Example
Collections Class asLifoQueue() method: Here, we are going to learn about the asLifoQueue() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on January 07, 2020
Collections Class asLifoQueue() method
- asLifoQueue() Method is available in java.lang package.
- asLifoQueue() Method is used to represent the given deque as a Lifo queue (LIFO means Last-in-First-Out).
- asLifoQueue() Method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
- asLifoQueue() Method does not throw an exception at the time of conversion from given Deque to LIFO Queue.
Syntax:
public static Queue asLifoQueue(Deque d);
Parameter(s):
- Deque d – represent the Deque.
Return value:
The return type of the method is Queue, it returns LIFO Queue.
Example:
// Java Program is to demonstrate the example
// of Queue asLifoQueue(Deque d) method of Collections class
import java.util.*;
public class AsLifoQueue {
public static void main(String args[]) {
// Create a array deque object
Deque de = new ArrayDeque(10);
// By using add() method is to add the
// given elements in linked list
de.add("C");
de.add("C++");
de.add("JAVA");
de.add("DOTNET");
de.add("PYTHON");
// Display Deque
System.out.println("de: " + de);
// By using asLifoQueue() method is to
// represent the deque elements as lifo queue
Queue lifo_q = Collections.asLifoQueue(de);
System.out.println();
System.out.println("Collections.asLifoQueue(de) :");
// Display Queue
System.out.println("lifo_q: " + lifo_q);
}
}
Output
de: [C, C++, JAVA, DOTNET, PYTHON]
Collections.asLifoQueue(de) :
lifo_q: [C, C++, JAVA, DOTNET, PYTHON]