--- jsr166/src/main/java/util/ArrayDeque.java 2016/10/30 16:50:05 1.100 +++ jsr166/src/main/java/util/ArrayDeque.java 2016/10/30 19:34:36 1.101 @@ -1112,11 +1112,12 @@ public class ArrayDeque extends Abstr if ((size = this.size) > a.length) return toArray((Class) a.getClass()); final Object[] es = elements; - final int head = this.head, end = head + size; - final int front = (es.length - end >= 0) ? size : es.length - head; - System.arraycopy(es, head, a, 0, front); - if (front < size) - System.arraycopy(es, 0, a, front, size - front); + int i, j, len, todo; + todo = size - (len = Math.min(size, es.length - (i = head))); + for (j = 0;; j += len, len = todo, todo = 0, i = 0) { + System.arraycopy(es, i, a, j, len); + if (todo == 0) break; + } if (size < a.length) a[size] = null; return a;