Returns 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.
package collection.demos;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Queue;
public class LifoQueue {
public static void main(String[] args) {
Deque<String> chars = new ArrayDeque<String>();
chars.add("A");
chars.add("B");
chars.add("C");
chars.add("D");
Queue<String> q = Collections.asLifoQueue(chars);
System.out.println("Queue : " + q);
}
}
/*
OUTPUT
Queue : [A, B, C, D]
*/
package collection.demos;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Queue;
public class LifoQueue {
public static void main(String[] args) {
Deque<String> chars = new ArrayDeque<String>();
chars.add("A");
chars.add("B");
chars.add("C");
chars.add("D");
Queue<String> q = Collections.asLifoQueue(chars);
System.out.println("Queue : " + q);
}
}
/*
OUTPUT
Queue : [A, B, C, D]
*/
Comments