12.6 Exercises
Last updated
Last updated
What methods are required for a class that is Iterable?
Which of the following is true about the java.util.Se
t and the java.util.List
interfaces?
Suppose we have a class that implements Iterator
. What methods must it override in order to compile?
Why do we want to override the .equals
method?
In lecture, you built the ArraySetIterator
class. Modify the lecture class to take in a Comparator<T>
and an item of generic type T
called ref
in the constructor. This new iterator should only return items greater than T
. For reference, the code for ArraySetIterator
is included below.
private class ArraySetIterator implements Iterator<T> {
private int pos;
public ArraySetIterator() {
pos = 0;
}
public boolean hasNext() {
return pos < size;
}
public T next() {
T returnItem = items[pos];
pos += 1;
return returnItem;
}
}
Problem 7 from the Spring 2018 Midterm 2