- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
作为 java 6 的一部分,在 Collections 实用程序类中添加了一个 asLifoQueue(Deque) 静态方法。
Javadoc 说
public static <T> Queue<T> asLifoQueue(Deque<T> deque)
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.
Each method invocation on the queue returned by this method results in exactly one method invocation on the backing deque, with one exception. The addAll method is implemented as a sequence of addFirst invocations on the backing deque.
现在这个和stack有什么区别。这本质上不是一个堆栈吗?
最佳答案
This view can be useful when you would like to use a method requiring a Queue but you need Lifo ordering.
该方法只是包装了 deque 参数,因此您可以处理 Queue
实现。正如你所说,队列只是一个堆栈,但是 javadoc Stack
类说:
A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example:
Deque<Integer> stack = new ArrayDeque<Integer>();
Deque
只是比 Stack
更完整,方法 asLifoQueue
只是一个将双端队列转换为类似堆栈的数据结构的实用程序.
关于java - 从 Collections.asLifoQueue(Deque) 和 Stack (Java 6) 返回的队列之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183797/
请参阅下面的代码片段: public class test1 { public static void main(String args[]) { Deque dq = new
作为 java 6 的一部分,在 Collections 实用程序类中添加了一个 asLifoQueue(Deque) 静态方法。 Javadoc 说 public static Queue asL
我是一名优秀的程序员,十分优秀!