June 2018
Intermediate to advanced
280 pages
7h 46m
English
Iterators are popular in most programming languages these days. It is probably most widely used in Java, along with the collections package. It is also implemented at the language level when a collection is traversed with the following loop construction:
for (String item : strCollection)System.out.println(item);
The iterator pattern can be implemented using the generics mechanism. This way, we can make sure we can avoid runtime errors generated by forced castings.
Good practice when implementing new containers and iterators in Java is to implement the existing java.util.Iterator<E> and java.util.Collection<E> classes. When we need aggregators with specific behaviors, we should also consider extending one of the ...
Read now
Unlock full access