View Single Post
Old 12-04-2007, 11:18 AM   #7 (permalink)
Zippygoose
Math Enthusiast/Badass MC
 
Zippygoose's Avatar
 
Join Date: Jun 2002
Location: Seattle
Posts: 650
+0 Internets
Send a message via AIM to Zippygoose
Quote:
Originally Posted by slitz View Post
Like Hachima so nicely showed, a Iterator can not give you a index nor can it find a specific object at a certain index. The reason is simple.
Iterator is just a object that goes through a collection to give you a "next" object. It's supposed to work on all collections, even randomAccessCollections, Sets etc, where the order is irrelevant, it can't give you a index since that would make the method or function invalid for other type of collections. Foreach loop uses a iterator, so you're not supposed to get the index when using a for each. If you want the index, use a normal for loop, since that is your own implementation.
I am filing this under "great interview questions" btw.
Zippygoose is offline   Reply With Quote

 
Uberguilds Network