Question: How to implement iterator. This is a java program. I have a boolean array and need to use an iterator although I am unsure of
How to implement iterator.
This is a java program. I have a boolean array and need to use an iterator although I am unsure of how to implement it. I don't need assistance in the BooleanArray class so will just share the portion for the variables. Thank you in advance for the help.
public class BooleanArray extends AbstractSet { private static final int DEFAULT_CAPACITY = 10;
private boolean[] data; private int manyItems;
}
I need help with thisIterator class.
private class thisIterator implements Iterator {
private int count = 0; // how many values have we seen (and not removed) private int currentIndex = -1;
@Override public boolean hasNext() { }
@Override public Integer next() {
if (!hasNext()) throw new NoSuchElementException("no more available"); return nextElement; }
@Override public void remove() { throw new UnsupportedOperationException("cannot remove element from bag");
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
