51 |
|
* Iterator} interfaces. |
52 |
|
* |
53 |
|
* <p>This class is a member of the |
54 |
< |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
54 |
> |
* <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework"> |
55 |
|
* Java Collections Framework</a>. |
56 |
|
* |
57 |
|
* @author Josh Bloch and Doug Lea |
181 |
|
* sufficient to hold 16 elements. |
182 |
|
*/ |
183 |
|
public ArrayDeque() { |
184 |
< |
elements = new Object[16]; |
184 |
> |
elements = new Object[16 + 1]; |
185 |
|
} |
186 |
|
|
187 |
|
/** |
209 |
|
*/ |
210 |
|
public ArrayDeque(Collection<? extends E> c) { |
211 |
|
this(c.size()); |
212 |
< |
addAll(c); |
212 |
> |
copyElements(c); |
213 |
|
} |
214 |
|
|
215 |
|
/** |
325 |
|
final int s, needed; |
326 |
|
if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0) |
327 |
|
grow(needed); |
328 |
< |
c.forEach(this::addLast); |
328 |
> |
copyElements(c); |
329 |
|
// checkInvariants(); |
330 |
|
return size() > s; |
331 |
|
} |
332 |
|
|
333 |
+ |
private void copyElements(Collection<? extends E> c) { |
334 |
+ |
c.forEach(this::addLast); |
335 |
+ |
} |
336 |
+ |
|
337 |
|
/** |
338 |
|
* Inserts the specified element at the front of this deque. |
339 |
|
* |