package iterators; import java.util.Iterator; import java.util.NoSuchElementException; public class ArrayIterator implements Iterator { private T[] array; private int index = 0; // index of the next element public ArrayIterator(T... array) { this.array = array; } public boolean hasNext() { return index < array.length; } public T next() { if (index >= array.length) throw new NoSuchElementException(); return array[index++]; } public void remove() { throw new UnsupportedOperationException(); } }