/** * Constructs an empty array deque with an initial capacity sufficient to * hold the specified number of elements. * * @param numElements * lower bound on initial capacity of the deque */ public ArrayDeque(int numElements) { allocateElements(numElements); }
/** * Deserialize this deque. */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read in size and allocate array int size = s.readInt(); allocateElements(size); head = 0; tail = size; // Read in all elements in the proper order. for (int i = 0; i < size; i++) elements[i] = (E) s.readObject(); } }
/** * Constructs a deque containing the elements of the specified collection, * in the order they are returned by the collection's iterator. (The first * element returned by the collection's iterator becomes the first element, * or <i>front</i> of the deque.) * * @param c * the collection whose elements are to be placed into the deque * @throws NullPointerException * if the specified collection is null */ public ArrayDeque(Collection< ? extends E> c) { allocateElements(c.size()); addAll(c); }