kk_oop<no spam> wrote:
> The reason I don't want to get a new one is because I will be iterating
> a particular list frequently, and I don't want to make a lot of objects
> for garbage collection.
Then I hope you don't also plan to ever modify the list once you start
passing the Iterator around, as any modification will make the Iterator
useless.
You are in any case probably trying to solve a problem that doesn't
exist -- modern VMs make use of a variety of techniques to reduce the
cost of garbage collection. With the default "generational" garbage
collector in recent Sun VMs, GCing "young" objects is very cheap indeed.
> I think what I can do is get a ListIterator and when I want to "reset"
> it, I can just loop through hasPrevious/previous until I'm back at the
> beginning. Seems like it should work.
That should work, in the sense that you can successfully return the
iterator to its initial state (or something close enough to it). It is
unlikely to be a performance win. (See Carl Howells' comments.)
John Bollinger