java.util.Collections.asLifoQueue() 方法
描述
asLifoQueue(Deque<T>) 方法用于将 Deque 视为后进先出 (Lifo) 队列。
声明
以下是 java.util.Collections.asLifoQueue() 方法的声明。
public static <T> Queue<T> asLifoQueue(Deque<T> deque)
参数
deque − 这是双端队列。
返回值
方法调用返回队列。
异常
NA
示例
下面的例子展示了 java.util.Collections.asLifoQueue() 的用法。
package com.tutorialspoint;
import java.util.*;
public class CollectionsDemo {
public static void main(String args[]) {
// create Deque object
Deque<Integer> deque = new ArrayDeque<Integer>(7);
// populate the object
deque.add(1);
deque.add(2);
deque.add(3);
deque.add(4);
deque.add(5);
deque.add(6);
deque.add(7);
// get queue from the deque
Queue nq = Collections.asLifoQueue(deque);
System.out.println("View of the queue is: "+nq);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
View of the queue is: [1, 2, 3, 4, 5, 6, 7]

