Does an instance of an Iterator opened on a collection keep the whole collection in memory and access a position that increments every time next() is called? Or am I missing something?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The implementation of
Iteratordepends on the particularCollectionit is iterating. If you look at the JDK source code,ArrayListandLinkedListfor example use different iterators.Remember
Iteratoris an interface not a concrete class so it simply specifies a contract not an implementation.Generally speaking iterators will (depending on the implementation) store a reference to the collection and some kind of index to mark where they’re up to.