import java.util.*;

        // Iterate over an array of objects.
class ArrayIterator implements Iterator {
        // Retain a reference to the data to be iterated over.
    public ArrayIterator(Object[] data){
        array = data;
    }

        // Definitions of the interface methods.
    public boolean hasNext(){
        return getLastIndex()+1 < getArray().length;
    }

    public Object next() throws NoSuchElementException {
        if(hasNext()){
            int index = getLastIndex()+1;
            // Update the value for next time.
            setLastIndex(index);
            return getArray()[index];
        }
        else{
            throw new NoSuchElementException();
        }
    }

        // Remove an element by setting it to null.
    public void remove() throws IllegalStateException,
                                UnsupportedOperationException {
        int index = getLastIndex();
        if(index < 0){
            throw new IllegalStateException();
        }
        else{
            getArray()[index] = null;
        }
    }

        // Accessors and mutators for the lastIndex and array attributes.
    private int getLastIndex(){
        return lastIndex;
    }

    private void setLastIndex(int n){
        lastIndex = n;
    }

    private Object[] getArray(){
        return array;
    }

    // The array of objects to be iterated over.
    private final Object[] array;
    // The index of the last element returned.
    private int lastIndex = -1;
}
