Exercises
-
(Collections) Here is the outline of a class that provides access to its data structure through an iterator. Write the iterator.
class storage { private Object[] data = new Object[256]; // don't allow access to anything not yet stored private int nextEmptySlot = 0; private int i=0; public Iterator iterator() { // returns a class that iterates over the data array return new Iterator() { // insert the body of the inner class here // 3 methods: remove(), hasNext(), next() }; }}
-
(Collections) Take the storage class from the previous question and add all the code necessary to make it implement the Collection interface. Make the type of the object stored a generic parameter. Limit the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access