645 |
|
|
646 |
|
/** |
647 |
|
* Returns an array containing all of the elements in this deque |
648 |
< |
* in the correct order. |
648 |
> |
* in proper sequence (from first to last element). |
649 |
> |
* |
650 |
> |
* <p>The returned array will be "safe" in that no references to it are |
651 |
> |
* maintained by this deque. (In other words, this method must allocate |
652 |
> |
* a new array). The caller is thus free to modify the returned array. |
653 |
> |
* |
654 |
> |
* <p>This method acts as bridge between array-based and collection-based |
655 |
> |
* APIs. |
656 |
|
* |
657 |
|
* @return an array containing all of the elements in this deque |
651 |
– |
* in the correct order |
658 |
|
*/ |
659 |
|
public Object[] toArray() { |
660 |
|
return copyElements(new Object[size()]); |
661 |
|
} |
662 |
|
|
663 |
|
/** |
664 |
< |
* Returns an array containing all of the elements in this deque in the |
665 |
< |
* correct order; the runtime type of the returned array is that of the |
666 |
< |
* specified array. If the deque fits in the specified array, it is |
667 |
< |
* returned therein. Otherwise, a new array is allocated with the runtime |
668 |
< |
* type of the specified array and the size of this deque. |
669 |
< |
* |
670 |
< |
* <p>If the deque fits in the specified array with room to spare (i.e., |
671 |
< |
* the array has more elements than the deque), the element in the array |
672 |
< |
* immediately following the end of the collection is set to <tt>null</tt>. |
664 |
> |
* Returns an array containing all of the elements in this deque in |
665 |
> |
* proper sequence (from first to last element); the runtime type of the |
666 |
> |
* returned array is that of the specified array. If the deque fits in |
667 |
> |
* the specified array, it is returned therein. Otherwise, a new array |
668 |
> |
* is allocated with the runtime type of the specified array and the |
669 |
> |
* size of this deque. |
670 |
> |
* |
671 |
> |
* <p>If this deque fits in the specified array with room to spare |
672 |
> |
* (i.e., the array has more elements than this deque), the element in |
673 |
> |
* the array immediately following the end of the deque is set to |
674 |
> |
* <tt>null</tt>. |
675 |
> |
* |
676 |
> |
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
677 |
> |
* array-based and collection-based APIs. Further, this method allows |
678 |
> |
* precise control over the runtime type of the output array, and may, |
679 |
> |
* under certain circumstances, be used to save allocation costs. |
680 |
> |
* |
681 |
> |
* <p>Suppose <tt>x</tt> is a deque known to contain only strings. |
682 |
> |
* The following code can be used to dump the deque into a newly |
683 |
> |
* allocated array of <tt>String</tt>: |
684 |
> |
* |
685 |
> |
* <pre> |
686 |
> |
* String[] y = x.toArray(new String[0]);</pre> |
687 |
> |
* |
688 |
> |
* Note that <tt>toArray(new Object[0])</tt> is identical in function to |
689 |
> |
* <tt>toArray()</tt>. |
690 |
|
* |
691 |
|
* @param a the array into which the elements of the deque are to |
692 |
|
* be stored, if it is big enough; otherwise, a new array of the |
693 |
|
* same runtime type is allocated for this purpose |
694 |
< |
* @return an array containing the elements of the deque |
695 |
< |
* @throws ArrayStoreException if the runtime type of a is not a supertype |
696 |
< |
* of the runtime type of every element in this deque |
694 |
> |
* @return an array containing all of the elements in this deque |
695 |
> |
* @throws ArrayStoreException if the runtime type of the specified array |
696 |
> |
* is not a supertype of the runtime type of every element in |
697 |
> |
* this deque |
698 |
> |
* @throws NullPointerException if the specified array is null |
699 |
|
*/ |
700 |
|
public <T> T[] toArray(T[] a) { |
701 |
|
int size = size(); |