public class PriorityQueue<E>extends AbstractQueue<E>implements Serializable
An unbounded priority queue based on a priority heap. This queue orders elements according to an order specified at construction time, which is specified either according to their natural order (see Comparable), or according to a Comparator, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException).
一個極大的優先隊列基于一個優先堆棧。這個隊列按照一個限定在構造時間順序排列元素,這是也是按照它們的自然的順序(查看Comparable)限定的,或者按照一個Comparator,依靠使用的構造子。一個優先隊列不允許為空元素。一個優先隊列依靠自然順序也不允許插入一個非comparable對象(這樣做會產生ClassCastException的結果)。
The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
這個隊列頭是最小的元素伴隨期望限定的排序。如果多個元素為最小的值約束,頭是這些元素中的一個---約束是任意打斷的。隊列獲得操作poll(推),remove(移除),peek 和在隊列頭部的元素
A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified.
一個優先隊列是極大的,但是擁有一個內部的容量調節數組的大小用來存儲在隊列中的元素。它總是至少和隊列大小是是一樣大小的。作為元素被加入一個優先隊列,它的容量是自動增加的。增加策略的細節是沒有指定的。
This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces. The Iterator provided in method iterator() is not guaranteed to traverse the elements of the PriorityQueue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()).
這個類和它的枚舉實現所有可選的集合和枚舉接口的方法。這個枚舉支持iterator()方法是不保證在任何特定的順序遍歷PriorityQueue的元素。如果你需要順序的遍歷,考慮使用Array.sort(pq.toArray()).
Note that this implementation is not synchronized. Multiple threads should not access a PriorityQueue instance concurrently if any of the threads modifies the list structurally. Instead, use the thread-safe PriorityBlockingQueue class.
注意這個實現不是不同步的。多個線程不應當并發訪問一個PriorityQueue實例,如果線程在結構上線程任一個被修改。作為替換,使用線程安全的PriorityBlockingQueue類。
Implementation note: this implementation provides O(log(n)) time for the insertion methods (offer, poll, remove() and add) methods; linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods (peek, element, and size).
This class is a member of the Java Collections Framework.
Since:
1.5
See Also:
Serialized Form