Is there an Iterator implementation that merges multiple iterators?
class MergedIterator<T> implements Iterator<T>
{
MergedIterator(Iterator<T>... iters)
....
}
And the next method should move on to iters[1] when !iters[0].hasNext() etc
I'd call that a ConcatenatedIterator myself - a MergedIterator should merge the results of several iterators e.g. based on sorting
Naming aside, I'm sure there'll be an implementation in a 3rd party library somewhere. Just off to check Google collections...
EDIT: Bingo - Iterators.concat
Commons Collections IteratorChain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With