Not sure I understand iterator implementation

I'm supposed to implement an iterator for the:

public class BinaryHeap> extends AbstractQueue

Class, and these are its attributes:

private static final int DEFAULT_CAPACITY = 100;

private int currentSize;

private AnyType [ ] array;

private boolean min;

private int modifications; //AKA "modcount"

The two methods that I had to implement (override?) are hasNext() next(); in addition, my iterator has to be fail-fast. This is my attempt:

private class HeapIterator implements Iterator


int expectedModCount = modifications;

int currentPosition;

public boolean hasNext()


return currentPosition < array.length;


public Object next() throws NoSuchElementException,




if (modifications != expectedModCount)

throw new ConcurrentModificationException();

return array[currentPosition++];


public void remove()


throw new...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts