public class LinkedBlockingDeque
extends AbstractQueue<E> implements BlockingDeque<E>, Serializable
| java.lang.Object | |||
| ↳ | java.util.AbstractCollection<E> | ||
| ↳ | java.util.AbstractQueue<E> | ||
| ↳ | java.util.concurrent.LinkedBlockingDeque<E> | ||
基于链接节点的可选有界的 blocking deque 。
可选的容量绑定构造函数参数用作防止过度扩展的一种方法。 如果未指定,容量等于MAX_VALUE 。 链接节点在每次插入时都会动态创建,除非这会导致deque超出容量。
大多数操作运行时间不变(忽略阻塞时间)。 例外包括remove , removeFirstOccurrence , removeLastOccurrence , contains , iterator.remove() ,和批量操作,所有这些都在运行线性时间。
该类及其迭代器实现了 Collection和 Iterator接口的所有 可选方法。
Public constructors |
|
|---|---|
LinkedBlockingDeque() 创建 |
|
LinkedBlockingDeque(int capacity) 用给定(固定)容量创建一个 |
|
LinkedBlockingDeque(Collection<? extends E> c) 创建 |
|
Public methods |
|
|---|---|
boolean |
add(E e) 在该双端队列的末尾插入指定的元素,除非它违反了容量限制。 |
void |
addFirst(E e) 如果可以立即执行而不违反容量限制,则将指定元素插入此双端队列的前端,如果当前没有可用空间,则抛出 |
void |
addLast(E e) 如果可以立即执行而不违反容量限制,则在该双端队列的末尾插入指定的元素,如果当前没有可用空间,则抛出 |
void |
clear() 从这个双动力系统中去除所有的元素。 |
boolean |
contains(Object o) 如果此双端队列包含指定的元素,则返回 |
Iterator<E> |
descendingIterator() 以相反顺序返回此双端队列中元素的迭代器。 |
int |
drainTo(Collection<? super E> c, int maxElements) 最多从此队列中移除给定数量的可用元素,并将它们添加到给定集合中。 |
int |
drainTo(Collection<? super E> c) 从该队列中移除所有可用的元素,并将它们添加到给定的集合中。 |
E |
element() 检索但不移除由此双端队列表示的队列头部。 |
E |
getFirst() 检索但不删除此双端队列的第一个元素。 |
E |
getLast() 检索但不删除此双端队列的最后一个元素。 |
Iterator<E> |
iterator() 以适当的顺序返回此双端队列中元素的迭代器。 |
boolean |
offer(E e, long timeout, TimeUnit unit) 将指定的元素插入到由此双端队列表示的队列中(换句话说,在此双端队列的尾部),如果有必要,等待达到指定的等待时间以使空间变为可用。 |
boolean |
offer(E e) 将指定的元素插入此双端队列表示的队列中(换句话说,在此双端队列的尾部),如果它是立即可行且不会违反容量限制,返回 |
boolean |
offerFirst(E e) 插入此双端队列的前面,如果它是立即可行且不会违反容量限制,返回指定的元素 |
boolean |
offerFirst(E e, long timeout, TimeUnit unit) 将指定的元素插入此双端队列的前端,如果有必要,等待指定的等待时间以使空间变为可用。 |
boolean |
offerLast(E e) 插入此双端队列的末尾,如果它是立即可行且不会违反容量限制,返回指定的元素 |
boolean |
offerLast(E e, long timeout, TimeUnit unit) 在指定的元素末尾插入指定的元素,如果需要,等待指定的等待时间以使空间变为可用。 |
E |
peek() 检索但不移除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),或者如果此双端队列为空,则返回 |
E |
peekFirst() 检索但不移除此双端队列的第一个元素,或者如果此双端队列为空,则返回 |
E |
peekLast() 检索但不移除此双端队列的最后一个元素,或者如果此双端队列为空,则返回 |
E |
poll(long timeout, TimeUnit unit) 检索并移除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),如果元素可用,则等待达到指定的等待时间(如果需要)。 |
E |
poll() 检索并移除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),或者如果此双端队列为空,则返回 |
E |
pollFirst() 检索并删除此双端队列的第一个元素,或者如果此双端队列为空,则返回 |
E |
pollFirst(long timeout, TimeUnit unit) 检索并删除此双端队列的第一个元素,如果需要,等待达到指定的等待时间,以使元素可用。 |
E |
pollLast(long timeout, TimeUnit unit) 检索并删除此双端队列的最后一个元素,如果元素变为可用,则等待达到指定的等待时间。 |
E |
pollLast() 检索并移除此双端队列的最后一个元素,或者如果此双端队列为空,则返回 |
E |
pop() 从由此双端队列表示的堆栈中弹出一个元素。 |
void |
push(E e) 如果可以立即执行而不违反容量限制, |
void |
put(E e) 将指定的元素插入到由此双端队列表示的队列中(换句话说,在此双端队列的尾部),等待必要的空间变为可用状态。 |
void |
putFirst(E e) 将指定的元素插入此双端队列的前端,如果需要,等待空间变为可用。 |
void |
putLast(E e) 在此双端队列的末尾插入指定的元素,如果需要,等待空间变为可用。 |
int |
remainingCapacity() 返回此双端队列可理想地(在没有内存或资源约束的情况下)无阻塞地接受的附加元素的数量。 |
E |
remove() 检索并删除由此双端队列表示的队列的头部。 |
boolean |
remove(Object o) 从此双端队列中移除指定元素的第一个匹配项。 |
E |
removeFirst() 检索并删除此双端队列的第一个元素。 |
boolean |
removeFirstOccurrence(Object o) 从此双端队列中移除指定元素的第一个匹配项。 |
E |
removeLast() 检索并删除此双端队列的最后一个元素。 |
boolean |
removeLastOccurrence(Object o) 从此双端队列中移除指定元素的最后一次出现。 |
int |
size() 返回此双端队列中的元素数量。 |
Spliterator<E> |
spliterator() 在此双端队列中的元素上返回 |
E |
take() 检索并移除由此双端队列表示的队列的头部(换句话说,此双端队列的第一个元素),如果有必要,则等待一个元素变为可用。 |
E |
takeFirst() 检索并删除此双端队列的第一个元素,如果需要等待,直到元素变为可用。 |
E |
takeLast() 检索并移除此双端队列的最后一个元素,如果需要,等待元素变为可用。 |
Object[] |
toArray() 以适当的顺序(从第一个元素到最后一个元素)返回包含此双端队列中所有元素的数组。 |
<T> T[] |
toArray(T[] a) 以适当的顺序返回包含此双端队列中所有元素的数组; 返回数组的运行时类型是指定数组的运行时类型。 |
String |
toString() 返回此集合的字符串表示形式。 |
Inherited methods |
|
|---|---|
java.util.AbstractQueue
|
|
java.util.AbstractCollection
|
|
java.lang.Object
|
|
java.util.Queue
|
|
java.util.Collection
|
|
java.util.concurrent.BlockingDeque
|
|
java.lang.Iterable
|
|
java.util.concurrent.BlockingQueue
|
|
java.util.Deque
|
|
LinkedBlockingDeque ()
创建 LinkedBlockingDeque ,容量 MAX_VALUE 。
LinkedBlockingDeque (int capacity)
用给定(固定)容量创建一个 LinkedBlockingDeque 。
| Parameters | |
|---|---|
capacity |
int: the capacity of this deque |
| Throws | |
|---|---|
IllegalArgumentException |
if capacity is less than 1 |
LinkedBlockingDeque (Collection<? extends E> c)
创建 LinkedBlockingDeque容量为 MAX_VALUE ,最初包含给定集合中的元素,添加在收集迭代器的遍历顺序。
| Parameters | |
|---|---|
c |
Collection: the collection of elements to initially contain |
| Throws | |
|---|---|
NullPointerException |
if the specified collection or any of its elements are null |
boolean add (E e)
在该双端队列的末尾插入指定的元素,除非它违反了容量限制。 当使用容量限制的双端队列时,通常最好使用方法offer 。
该方法相当于 addLast(E) 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Returns | |
|---|---|
boolean |
true (as specified by add(E)) |
| Throws | |
|---|---|
IllegalStateException |
if this deque is full |
NullPointerException |
if the specified element is null |
void addFirst (E e)
如果可以立即执行而不违反容量限制,则将指定元素插入此双端队列的前端,如果当前没有可用空间,则抛出IllegalStateException 。 当使用容量限制的双端队列时,通常最好使用offerFirst 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Throws | |
|---|---|
IllegalStateException |
if this deque is full |
NullPointerException |
|
void addLast (E e)
如果可以立即执行而不违反容量限制,则在此双端队列的末尾插入指定的元素,如果当前没有可用空间,则抛出IllegalStateException 。 当使用容量限制的双端队列时,通常最好使用offerLast 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Throws | |
|---|---|
IllegalStateException |
if this deque is full |
NullPointerException |
|
boolean contains (Object o)
如果此双端队列包含指定的元素,则返回true 。 更正式地说,返回true当且仅当该双端包含至少一个元素e例如o.equals(e) 。
| Parameters | |
|---|---|
o |
Object: object to be checked for containment in this deque |
| Returns | |
|---|---|
boolean |
true if this deque contains the specified element |
Iterator<E> descendingIterator ()
以相反顺序返回此双端队列中元素的迭代器。 元素将从上一个(尾)到第一个(头)的顺序返回。
返回的迭代器是 weakly consistent 。
| Returns | |
|---|---|
Iterator<E> |
an iterator over the elements in this deque in reverse order |
int drainTo (Collection<? super E> c, int maxElements)
最多从此队列中移除给定数量的可用元素,并将它们添加到给定集合中。 尝试将元素添加到集合c遇到的故障可能导致元素不在任何集合中,或者在引发关联的异常时集合都不集中。 尝试将队列IllegalArgumentException自身导致IllegalArgumentException 。 此外,如果在操作正在进行时修改了指定的集合,则此操作的行为未定义。
| Parameters | |
|---|---|
c |
Collection: the collection to transfer elements into |
maxElements |
int: the maximum number of elements to transfer |
| Returns | |
|---|---|
int |
the number of elements transferred |
| Throws | |
|---|---|
UnsupportedOperationException |
|
ClassCastException |
|
NullPointerException |
|
IllegalArgumentException |
|
int drainTo (Collection<? super E> c)
从该队列中移除所有可用的元素,并将它们添加到给定的集合中。 该操作可能比重复轮询该队列更有效。 尝试将元素添加到集合c遇到的故障可能导致元素不在任何集合中,或者在引发关联异常时集合中的任何一个集合或两个集合都不在元素中。 尝试排队到自己导致IllegalArgumentException 。 此外,如果在操作正在进行时修改了指定的集合,则此操作的行为未定义。
| Parameters | |
|---|---|
c |
Collection: the collection to transfer elements into |
| Returns | |
|---|---|
int |
the number of elements transferred |
| Throws | |
|---|---|
UnsupportedOperationException |
|
ClassCastException |
|
NullPointerException |
|
IllegalArgumentException |
|
E element ()
检索但不移除由此双端队列表示的队列头部。 此方法与peek仅在于,如果此双端队列为空,则会引发异常。
这种方法相当于 getFirst 。
| Returns | |
|---|---|
E |
the head of the queue represented by this deque |
| Throws | |
|---|---|
NoSuchElementException |
if this deque is empty |
E getFirst ()
检索但不删除此双端队列的第一个元素。 此方法与peekFirst仅在于,如果此双端队列为空,则会引发异常。
| Returns | |
|---|---|
E |
the head of this deque |
| Throws | |
|---|---|
NoSuchElementException |
|
E getLast ()
检索但不删除此双端队列的最后一个元素。 此方法与peekLast仅在于,如果此双端队列为空,则会引发异常。
| Returns | |
|---|---|
E |
the tail of this deque |
| Throws | |
|---|---|
NoSuchElementException |
|
Iterator<E> iterator ()
以适当的顺序返回此双端队列中元素的迭代器。 元素将从第一个(头部)到最后一个(尾部)按顺序返回。
返回的迭代器是 weakly consistent 。
| Returns | |
|---|---|
Iterator<E> |
an iterator over the elements in this deque in proper sequence |
boolean offer (E e,
long timeout,
TimeUnit unit)
将指定的元素插入到由此双端队列表示的队列中(换句话说,在此双端队列的尾部),如果有必要,等待达到指定的等待时间以使空间变为可用。
该方法相当于 offerLast 。
| Parameters | |
|---|---|
e |
E: the element to add |
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
boolean |
true if the element was added to this deque, else false |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
boolean offer (E e)
将指定的元素插入此双端队列表示的队列中(换句话说,在此双端队列的尾部),如果它是立即可行且不会违反容量限制,返回true在成功和false ,如果当前没有空间可用。 当使用容量受限deque时,这种方法通常比add(E)方法更可取,它只能通过抛出异常来插入元素。
这种方法相当于 offerLast 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Returns | |
|---|---|
boolean |
true if the element was added to this deque, else false |
| Throws | |
|---|---|
NullPointerException |
if the specified element is null |
boolean offerFirst (E e)
插入此双端队列的前面,如果它是立即可行且不会违反容量限制,返回指定的元素true在成功false如果当前没有空间可用。 当使用容量限制的双端队列时,此方法通常比addFirst方法更可取,该方法只能通过抛出异常才能插入元素。
| Parameters | |
|---|---|
e |
E: the element to add |
| Returns | |
|---|---|
boolean |
true if the element was added to this deque, else false |
| Throws | |
|---|---|
NullPointerException |
|
boolean offerFirst (E e,
long timeout,
TimeUnit unit)
将指定的元素插入此双端队列的前端,如果有必要,等待指定的等待时间以使空间变为可用。
| Parameters | |
|---|---|
e |
E: the element to add |
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
boolean |
true if successful, or false if the specified waiting time elapses before space is available |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
boolean offerLast (E e)
插入此双端队列的末尾,如果它是立即可行且不会违反容量限制,返回指定的元素true在成功false如果当前没有空间可用。 当使用容量受限deque时,这种方法通常比addLast方法更可取,它只能通过抛出异常来插入元素。
| Parameters | |
|---|---|
e |
E: the element to add |
| Returns | |
|---|---|
boolean |
true if the element was added to this deque, else false |
| Throws | |
|---|---|
NullPointerException |
|
boolean offerLast (E e,
long timeout,
TimeUnit unit)
在指定的元素末尾插入指定的元素,如果需要,等待指定的等待时间以使空间变为可用。
| Parameters | |
|---|---|
e |
E: the element to add |
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
boolean |
true if successful, or false if the specified waiting time elapses before space is available |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
E peek ()
检索但不移除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),或者如果此双端队列为空,则返回 null 。
这种方法相当于 peekFirst 。
| Returns | |
|---|---|
E |
the head of this deque, or null if this deque is empty |
E peekFirst ()
检索但不移除此双端队列的第一个元素,或者如果此双端队列为空,则返回 null 。
| Returns | |
|---|---|
E |
the head of this deque, or null if this deque is empty |
E peekLast ()
检索但不移除此双端队列的最后一个元素,或者如果此双端队列为空,则返回 null 。
| Returns | |
|---|---|
E |
the tail of this deque, or null if this deque is empty |
E poll (long timeout,
TimeUnit unit)
检索并移除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),如果元素可用,则等待达到指定的等待时间(如果需要)。
此方法相当于 pollFirst 。
| Parameters | |
|---|---|
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
E |
the head of this deque, or null if the specified waiting time elapses before an element is available |
| Throws | |
|---|---|
InterruptedException |
|
E poll ()
检索并删除由此双端队列表示的队列头(换句话说,此双端队列的第一个元素),或者如果此双端队列为空,则返回 null 。
此方法相当于 pollFirst() 。
| Returns | |
|---|---|
E |
the head of this deque, or null if this deque is empty |
E pollFirst ()
检索并删除此双端队列的第一个元素,或者如果此双端队列为空,则返回 null 。
| Returns | |
|---|---|
E |
the head of this deque, or null if this deque is empty |
E pollFirst (long timeout,
TimeUnit unit)
检索并删除此双端队列的第一个元素,如果需要,等待达到指定的等待时间,以使元素可用。
| Parameters | |
|---|---|
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
E |
the head of this deque, or null if the specified waiting time elapses before an element is available |
| Throws | |
|---|---|
InterruptedException |
|
E pollLast (long timeout,
TimeUnit unit)
检索并删除此双端队列的最后一个元素,如果元素变为可用,则等待达到指定的等待时间。
| Parameters | |
|---|---|
timeout |
long: how long to wait before giving up, in units of unit |
unit |
TimeUnit: a TimeUnit determining how to interpret the timeout parameter |
| Returns | |
|---|---|
E |
the tail of this deque, or null if the specified waiting time elapses before an element is available |
| Throws | |
|---|---|
InterruptedException |
|
E pollLast ()
检索并移除此双端队列的最后一个元素,或者如果此双端队列为空,则返回 null 。
| Returns | |
|---|---|
E |
the tail of this deque, or null if this deque is empty |
E pop ()
从由此双端队列表示的堆栈中弹出一个元素。 换句话说,删除并返回此双端队列的第一个元素。
该方法相当于 removeFirst() 。
| Returns | |
|---|---|
E |
the element at the front of this deque (which is the top of the stack represented by this deque) |
| Throws | |
|---|---|
NoSuchElementException |
|
void push (E e)
如果可以在不违反容量限制的情况下立即执行此操作,则将元素推入由此双端队列表示的堆栈(即,在此双端队列的头部),如果当前没有可用空间,则抛出 IllegalStateException 。
该方法相当于 addFirst 。
| Parameters | |
|---|---|
e |
E: the element to push |
| Throws | |
|---|---|
IllegalStateException |
if this deque is full |
NullPointerException |
|
void put (E e)
将指定的元素插入到由此双端队列表示的队列中(换句话说,在此双端队列的尾部),等待必要的空间变为可用状态。
此方法相当于 putLast 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
void putFirst (E e)
将指定的元素插入此双端队列的前端,如果需要,等待空间变为可用。
| Parameters | |
|---|---|
e |
E: the element to add |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
void putLast (E e)
在此双端队列的末尾插入指定的元素,如果需要,等待空间变为可用。
| Parameters | |
|---|---|
e |
E: the element to add |
| Throws | |
|---|---|
NullPointerException |
|
InterruptedException |
|
int remainingCapacity ()
返回此双端队列可理想地(在没有内存或资源约束的情况下)无阻塞地接受的附加元素的数量。 这总是等于这个双代的初始容量减去当前这个双代的size 。
请注意,您 不能总是通过检查 remainingCapacity来判断尝试插入元素是否成功,因为可能是另一个线程即将插入或移除元素。
| Returns | |
|---|---|
int |
the remaining capacity |
E remove ()
检索并删除由此双端队列表示的队列的头部。 此方法与poll仅在于,如果此双端队列为空,则会引发异常。
这种方法相当于 removeFirst 。
| Returns | |
|---|---|
E |
the head of the queue represented by this deque |
| Throws | |
|---|---|
NoSuchElementException |
if this deque is empty |
boolean remove (Object o)
从此双端队列中移除指定元素的第一个匹配项。 如果该deque不包含该元素,则该值不变。 更正式地,删除第一个元素e ,使得o.equals(e) (如果存在这样的元素)。 如果此双端队列包含指定的元素(或者等价地,如果此双端队列由于调用而更改),则返回true 。
该方法相当于 removeFirstOccurrence 。
| Parameters | |
|---|---|
o |
Object: element to be removed from this deque, if present |
| Returns | |
|---|---|
boolean |
true if this deque changed as a result of the call |
E removeFirst ()
检索并删除此双端队列的第一个元素。 此方法与pollFirst仅在于,如果此双端队列为空,则会引发异常。
| Returns | |
|---|---|
E |
the head of this deque |
| Throws | |
|---|---|
NoSuchElementException |
|
boolean removeFirstOccurrence (Object o)
从此双端队列中移除指定元素的第一个匹配项。 如果该deque不包含该元素,则该值不变。 更正式地,删除第一个元素e ,使得o.equals(e) (如果存在这样的元素)。 如果此双端队列包含指定的元素(或者等价地,如果此双端队列由于调用而更改),则返回true 。
| Parameters | |
|---|---|
o |
Object: element to be removed from this deque, if present |
| Returns | |
|---|---|
boolean |
true if an element was removed as a result of this call |
E removeLast ()
检索并删除此双端队列的最后一个元素。 该方法与pollLast仅在于,如果此双端队列为空,则会引发异常。
| Returns | |
|---|---|
E |
the tail of this deque |
| Throws | |
|---|---|
NoSuchElementException |
|
boolean removeLastOccurrence (Object o)
从此双端队列中移除指定元素的最后一次出现。 如果该deque不包含该元素,则该值不变。 更正式地说,删除最后一个元素e ,使得o.equals(e) (如果存在这样的元素)。 如果此双端队列包含指定的元素(或者等价地,如果此双端队列因呼叫而改变),则返回true 。
| Parameters | |
|---|---|
o |
Object: element to be removed from this deque, if present |
| Returns | |
|---|---|
boolean |
true if an element was removed as a result of this call |
int size ()
返回此双端队列中的元素数量。
| Returns | |
|---|---|
int |
the number of elements in this deque |
Spliterator<E> spliterator ()
通过此双端队列中的元素返回 Spliterator 。
返回的分隔符是 weakly consistent 。
该 Spliterator报告 CONCURRENT , ORDERED ,并 NONNULL 。
Spliterator implements trySplit to permit limited parallelism.| Returns | |
|---|---|
Spliterator<E> |
a Spliterator over the elements in this deque |
E take ()
检索并移除由此双端队列表示的队列的头部(换句话说,此双端队列的第一个元素),如果有必要,则等待一个元素变为可用。
这种方法相当于 takeFirst 。
| Returns | |
|---|---|
E |
the head of this deque |
| Throws | |
|---|---|
InterruptedException |
|
E takeFirst ()
检索并删除此双端队列的第一个元素,如果需要等待,直到元素变为可用。
| Returns | |
|---|---|
E |
the head of this deque |
| Throws | |
|---|---|
InterruptedException |
|
E takeLast ()
检索并移除此双端队列的最后一个元素,如果需要,等待元素变为可用。
| Returns | |
|---|---|
E |
the tail of this deque |
| Throws | |
|---|---|
InterruptedException |
|
Object[] toArray ()
以适当的顺序(从第一个元素到最后一个元素)返回包含此双端队列中所有元素的数组。
返回的数组将是“安全的”,因为此双端队列没有引用它。 (换句话说,这个方法必须分配一个新的数组)。 调用者可以自由修改返回的数组。
此方法充当基于数组和基于集合的API之间的桥梁。
| Returns | |
|---|---|
Object[] |
an array containing all of the elements in this deque |
T[] toArray (T[] a)
以适当的顺序返回包含此双端队列中所有元素的数组; 返回数组的运行时类型是指定数组的运行时类型。 如果deque适合指定的数组,则返回其中。 否则,将使用指定数组的运行时类型和此双端队列的大小分配一个新数组。
如果此双端队列在指定阵列中有空余空间(即阵列中的元素多于此双端队列),那么阵列中紧跟在双端队列后面的元素将设置为 null 。
与toArray()方法一样,此方法充当基于数组和基于集合的API之间的桥梁。 此外,该方法允许精确控制输出数组的运行时类型,并且在某些情况下可以用于节省分配成本。
假设x是一个已知只包含字符串的deque。 下面的代码可以用于将deque转储到新分配的String数组中:
String[] y = x.toArray(new String[0]); Note that
toArray(new Object[0]) is identical in function to
toArray().
| Parameters | |
|---|---|
a |
T: the array into which the elements of the deque are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose |
| Returns | |
|---|---|
T[] |
an array containing all of the elements in this deque |
| Throws | |
|---|---|
ArrayStoreException |
if the runtime type of the specified array is not a supertype of the runtime type of every element in this deque |
NullPointerException |
if the specified array is null |
String toString ()
返回此集合的字符串表示形式。 字符串表示由收集元素的列表组成,它们按其迭代器返回的顺序包含在方括号( "[]" )中。 相邻的元素由字符", " (逗号和空格)分隔。 元素被转换为字符串,如valueOf(Object) 。
| Returns | |
|---|---|
String |
a string representation of this collection |