T
- public class MergeIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>
Merges multiple iterators and produces elements according to the provided comparator.
The input iterators do not need to be sorted. However, if two iterators produce the same element at the same time, the element will only be output once.
eg, for inputs [1, 2, 3] and [0, 1, 2], the output will be [0, 1, 2, 3]
however, for inputs [1, 2, 1] and [1, 3, 2], the output will be [1, 2, 1, 3, 2]
Constructor and Description |
---|
MergeIterator(java.util.Comparator<? super T> comparator,
java.util.Iterator<T>... iterators) |
MergeIterator(java.util.List<java.util.Iterator<T>> iterators,
java.util.Comparator<? super T> comparator) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
T |
next() |