July 2018
Intermediate to advanced
266 pages
7h 11m
English
In some cases, you want to retrieve all the elements of an iterator at once, instead of doing it one by one. Notice that because we are talking about this topic from the point of view of a data source, our use case is more oriented towards getting one element or a group of them at a time.
You can use the functions forEach() and forEachRemaining() to go through the whole iterator. Because an iterator can only go forward, both functions will work the same:
iterator.forEach { println(it)}
Read now
Unlock full access