Login | Register    RSS Feed Download our iPhone app Browse DevX
Sign up for e-mail newsletters from DevX   Creating Custom
Generic Collections with J2SE 5.0 : Page 3  J2SE 5.0 introduced
many additions to the collections API that you need to be aware
of to properly implement generic custom collections that work
seamlessly with multiple types and the new "for each" construct.
Creating a Peekable Stack Iterator If the PeekableStack class is
to be used with Java's new "for each" construct, then you must
create a "Java Standard" iterator. The implementation for a
PeekableStackIterator class is shown in Listing 3.  In Listing
3, the iterator does not actually change the value of the stack
in any way; instead, the iterator keeps track of its current
position in the element list and always returns the next
element. Because this information is stored in the iteration
class itself, it would be possible to have several iterators
operating on the same stack.  The following program tests the
Peekable stack.  package co