Given the following code snippet:
int[] arr = {1, 2, 3};
for (int i : arr)
System.out.println(i);
I have the following questions:
public class ArrayIterator implements Iterator {
private T array[];
private int pos = 0;
public ArrayIterator(T anArray[]) {
array = anArray;
}
public boolean hasNext() {
return pos < array.length;
}
public T next() throws NoSuchElementException {
if (hasNext())
return array[pos++];
else
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException();
}
}