Skip to main content
gamedev.net
🔒 Locked

[java] Iterator question

Started by Lucidquiet 2 replies 750+ views
Original Post
Lucidquiet
Lucidquiet
Curious if anyone knows if the Iterator returned from most of the Java Util Collection classes is created when requested, or if it is just an object that can traverse the backing store? L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Son of Cain
Son of Cain
It not only traverses the Collection, it can also perform one single modification to it: remove().

Iterator < GameObject > gObjs = readyToFree.iterator();while ( gObjs.hasNext() ) {  it.next().freeResources();  it.remove();}


As per its creation, I think (but I'm not sure) they are just an object that can traverse the backing store. But since we have different Iterator implementations in the API, there can be different behaviors for their instatiation as well. I don't know the API in deep detail to answer that, but the above note seemed necessary, so I posted ;)

Son Of Cain
a.k.a javabeats at yahoo.ca
nmi
nmi
Since the source code of the API is part of suns JDK, you can easily have a look.
At least for JDK1.5, it is created when you call AbstractList.iterator() via new.
Lucidquiet
Lucidquiet
Thanks Son of Cain

Quote:
Original post by nmi
Since the source code of the API is part of suns JDK, you can easily have a look.
At least for JDK1.5, it is created when you call AbstractList.iterator() via
new.


Yeah, I realize -- but I was wonderring if someone knew -- I I'll check what the case is.

L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.