Old Business Get LStack.java
tested and working.
You can download the code in yesterday's page.
Implementing Iterable<T>
This interface specifies one method, iterator()
.
What's an iterator?
An Iterator<T>
specifies three methods.
boolean hasNext()
Returnstrue
if the iteration has more elements.boolean next()
Returns the next element in the iteration.boolean remove()
Removes from the underlying collection the last element returned by this iterator (optional operation). Throw anUnsupportedOperatorException
to ditch this.
Why subject ourselves to this torture? If you do this, the
collections for
loop will work for your data structure. Wanna look
like a pro or an ammie-ture?
We are going to to this to our stack classes.