Collections.asLifoQueue(Deque<E>): This method is available in java.util.Collections class of Java.
Syntax:
<E> Queue<E> java.util.Collections.asLifoQueue(Deque<E> deque)
This method takes one argument. This method returns a view of a Deque as a Last-in-first-out (Lifo) Queue.
Note: Method add is mapped to push, remove is mapped to pop, and so on.
Parameters: One parameter is required for this method.
deque: the deque
Returns: the queue.
Exceptions: NA
Approach
Java
import java.util.Collections;import java.util.Deque;import java.util.LinkedList;public class CollectionsasLifoQueue {public static void main(String[] args) {Deque<Integer> deque = new LinkedList<Integer>();deque.add(10);deque.add(12);deque.add(10);System.out.println(Collections.asLifoQueue(deque));}}
Output:
[10, 12, 10]
No comments:
Post a Comment