Queue resizing array implementation After learning about linked list implementations of a queue I was asked to try a resizing array implementation. I'm looking for constructive criticism.

import java.util.NoSuchElementException;

/**
 * ResizingQueue - Resizing Array Implementation.
 *
 * @author Rocky
 * @version 2016-05-31 
 */
public class ResizingQueue&lt;Item&gt; {

    private Item[] queue;
    private int size;
    private int index;

    public ResizingQueue() {
        queue = (Item[]) new Object[1];
        size = 0;
        index = 0;
    }

    /**
     * Returns the size of the queue
     *
     * @return Integer representing the number of items in the queue
     */
    public int size() {
        return this.size;
    }

    /**
     * Returns whether or not the queue is empty
     *
     * @return True if the queue is empty
     */  
    public boolean isEmpty(){
        return size == 0;
    }

    /**
     * Adds an item onto the end of the queue. If the size of the queue reaches
     * the length of the array, the length of the array is doubled.
     *
     * @param item Item to be added. Must not be null
     * @throws NullPointerException if the parameter item is null
     */
    public void enqueue(Item item) {
        if (item == null) {
            throw new NullPointerException("Item must not be null");
        }
        if (size == queue.length) {
            resize(2 * queue.length);
        }
        queue[size + index] = item;
        size++;
    }

    /**
     * Removes and returns the item at the front of the queue. If the size of
     * the queue reaches 25% of the length of the array, the length of the array
     * is halved.
     *
     * @return Item at the front of the queue
     * @throws NoSuchElementException if dequeue() is called while the queue is
     * empty
     */
     public Item dequeue() {
        if (isEmpty()) {
            throw new NoSuchElementException("There is nothing in the queue");
        }
        if (size &lt; queue.length / 4) {
            resize(queue.length / 2);
            index = 0;
        }
        Item item = queue[index];
        queue[index++] = null;
        size--;
        return item;
    }

    /**
     * Resizes the array when capacity reaches 100% or 25%
     *
     * @param capacity New capacity for the array
     */
    private void resize(int capacity) {
        Item[] copy = (Item[]) new Object[capacity];
        for (int i = 0; i &lt; size; i++) {
            copy[i] = queue[i + index];
        }
        queue = copy;
    }

}
Your code looks good, but can be improved.  


/**
 * Resizes the array when capacity reaches 100% or 25%
 *
 * @param capacity New capacity for the array
 */
private void resize(int capacity) {
    Item[] copy = (Item[]) new Object[capacity];
    for (int i = 0; i &lt; size; i++) {
        copy[i] = queue[i + index];
    }
    queue = copy;
}  



The javadoc states that this method would resize the array when the capacity reaches a specific value which isn't correct. This method resizes the underlaying buffer no matter what capacity it has.  

This javadoc is lying. After removing the lying part only Resizes the array is left as description which basically doesn't add any value because it is obvious.  

I would remove that javadoc completely and rename the method to resizeInternalBuffer.  



enqueue()


/**
 * Adds an item onto the end of the queue. If the size of the queue reaches
 * the length of the array, the length of the array is doubled.
 *
 * @param item Item to be added. Must not be null
 * @throws NullPointerException if the parameter item is null
 */



Without reading the code I see that this method (and the dequeue() method as well) is doing too much. I would extract the checking for the size to separate methods like so  

private void ensureCapacityMax() {
    if (size == queue.length) {
        resize(2 * queue.length);
    }
}

private void ensureCapacityMin() {
    if (size &lt; queue.length / 4) {
        resize(queue.length / 2);
    }
}  


which are then called like  

public void enqueue(Item item) {
    if (item == null) {
        throw new NullPointerException("Item must not be null");
    }

    ensureCapacityMax();

    queue[size + index] = item;
    size++;
}


By using lambda expressions you could simplify this to one method.  



I don't really like the usage of index for enqueue() and dequeue(). A much cleaner way would be to use head and tail like so  

private int head = 0;
private int tail = 0;  

public void enqueue(Item item) {
    if (item == null) {
        throw new NullPointerException("Item must not be null");
    }

    ensureCapacityMax()

    queue[tail] = item;
    tail = (tail + 1) % queue.length;
    size++;
}


public Item dequeue() {
    if (isEmpty()) {
        throw new NoSuchElementException("There is nothing in the queue");
    }

    ensureCapacityMin()

    Item item = queue[head];
    queue[head] = null;
    head = (head + 1) % queue.length;
    size--;
    return item;
}   


now we need to adjust the resize() method like so by the usage of System.arraycopy()  

private void resize(int capacity) {
    Item[] copy = (Item[]) new Object[capacity];

    if (size &gt; 0) {
        if (head &lt; tail) {
            System.arraycopy(queue, head, copy, 0, size);
        } else {
            System.arraycopy(queue, head, copy, 0, queue.length - head);
            System.arraycopy(queue, 0, copy, queue.length - head, tail);
        }
    }

    queue = copy;
    head = 0;
    tail = (size == capacity) ? 0 : size; 
}


I didn't test this implementation but it should work well.