O'Reilly logo

Program Development in Java: Abstraction, Specification, and Object-Oriented Design by John Guttag, Barbara Liskov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6 Iteration Abstraction

This chapter discusses our final abstraction mechanism, the iteration abstraction, or iterator for short. Iterators are a generalization of the iteration mechanisms available in most programming languages. They permit users to iterate over arbitrary types of data in a convenient and efficient way.

For example, an obvious use of a set is to perform some action for each of its elements:

for all elements of the set    do action

Such a loop might go through the set completely—for example, to sum all elements of a set. Or it might search for an element that satisfies some criterion, in which case the loop can stop as soon as the desired element has been found.

IntSets as we have defined them so far provide no convenient way ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required