Lecture 3
Lecture 3
Lecture 3
Iteration Abstraction
Outline
• Iteration
• Why iteration abstraction?
• Generator
• Iteration in Java
• Implement an iteration
• Using iteration
References
• Notes:
• hasNext() and next() both check if there are more results to return
• next(): modifies the state of generator if a new result is returned
• remove(): only used for modifiable collections
Multiple iterators
iterator()
rIterator()
An independent reverse iterator
Example: LinkedList
Example: LinkedList
LinkedList