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 ...
Get Just Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.