From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: The Iterator pattern

Challenge: The Iterator pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Challenge: The Iterator pattern

(upbeat music) - [Narrator] Let's have a look at our next exercise. In this one, there is an app that keeps a record of employees, and the exercise is to use the iterator pattern, to traverse the list and print out the name of each employee. So the app has a class called employee, and this has a single field of type string called name. A name gets passed into the constructor and there is a get named method, which returns the name. Next, there's a main class, which has a main method in it. In here, three employees are created, Zack, Sarah and Anna. There are also two more classes which are empty at the moment. The first is called staff list, and this is going to be the collection of employees that you need to iterate over. The last class is called staff list iterator which will be the iterator used to iterate over the employees in the staff list. As with the example in the previous video, feel free to make use…

Contents