A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit.
This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either null or false, depending on the operation). The latter form of the insert operation is designed specifically for use with capacity-restricted Deque implementations; in most implementations, insert operations cannot fail.
翻译:
支持两端元素插入和移除的线性集合。deque这个名字是“双端队列”的缩写,通常读作“deck”。大多数Deque实现对它们可能包含的元素数量没有固定的限制,但是这个接口支持容量限制的Deque以及那些没有固定大小限制的Deque。
这个接口定义了访问deque容器两端元素的方法。提供了插入、删除和检查元素的方法。这些方法以两种形式存在:一种在操作失败时抛出异常,另一种返回特殊值(null或false,取决于操作)。插入操作的后一种形式是专门为使用容量受限的Deque实现而设计的;在大多数实现中,插入操作不会失败。
The twelve methods described above are summarized in the following table:
下表总结了上述12种方法:
This interface extends the Queue interface. When a deque is used as a queue, FIFO (First-In-First-Out) behavior results. Elements are added at the end of the deque and removed from the beginning. The methods inherited from the Queue interface are precisely equivalent to Deque methods as indicated in the following table:
翻译:
本接口扩展了Queue接口。当deque被用作队列时,会产生FIFO(先进先出)行为。在deque容器的末尾添加元素,并从开头删除元素。从Queue接口继承的方法完全等同于Deque方法,如下表所示:
Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Stack methods are precisely equivalent to Deque methods as indicated in the table below:
翻译:
deque也可以用作LIFO (Last-In-First-Out)栈。应该优先使用这个接口而不是遗留的Stack类。当一个deque容器被用作栈时,元素会从deque容器的开头被推送和弹出。Stack方法与Deque方法完全等价,如下表所示:
Note that the peek method works equally well when a deque is used as a queue or a stack; in either case, elements are drawn from the beginning of the deque.
This interface provides two methods to remove interior elements, removeFirstOccurrence and removeLastOccurrence.
Unlike the List interface, this interface does not provide support for indexed access to elements.
While Deque implementations are not strictly required to prohibit the insertion of null elements, they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encouraged not to take advantage of the ability to insert nulls. This is so because null is used as a special return value by various methods to indicated that the deque is empty.
Deque implementations generally do not define element-based versions of the equals and hashCode methods, but instead inherit the identity-based versions from class Object.
This interface is a member of the Java Collections Framework.
Since:
1.6
Author:
Doug Lea, Josh Bloch
Type parameters:
<E> – the type of elements held in this collection
翻译:
注意,当deque被用作队列或堆栈时,peek方法同样有效;在这两种情况下,元素都是从deque容器的开头抽取的。
这个接口提供了两个方法来删除内部元素:removeFirstOccurrence和removeLastOccurrence。
与List接口不同,此接口不支持对元素的索引访问。
虽然Deque实现并没有严格要求禁止插入空元素,但强烈建议这样做。任何允许空元素的Deque实现的用户都强烈建议不要利用插入空元素的功能。这是因为null被各种方法用作特殊返回值来指示deque为空。
Deque实现通常不定义equals方法和hashCode方法的基于元素的版本,而是从类Object继承基于身份的版本。
该接口是Java集合框架的成员。
自:
1.6
作者:
Doug Lea, Josh Bloch
类型参数:
-该集合中包含的元素类型
小结:
1、Deque是支持两端元素插入和移除的线性集合,既可以用作队列,也可以用作栈,而且源码作者强烈建议使用Deque而不是遗留的Stack类。
2、当Deque用作队列时,Deque与队列的等同方法见图2.
3、当Deque用作栈时,Deque与栈的等同方法见图3.