DEV Community

loading...

Discussion on: Iterator Pattern

Collapse
pjotre86 profile image
pjotre86 • Edited

Thanks!
Would you please help me to understand when this level of abstraction is actually useful?
I'm asking because in this example 99% of all java developers would probably just do a

items.forEach(System.out::println);
Collapse
eidher profile image
eidher Author • Edited

forEach is a defult method of the Iterable interface which uses the java.util.Iterator interface. So, at the end of the day, implicitly is the same. Of course, we do not need to reinvent the wheel. I would use your code.