Java Utililty Methods Iterator

List of utility methods to do Iterator

Description

The list of methods to do Iterator are organized into topic(s).

Method

ListlistOfIterator(Iterator iterator)
list Of Iterator
List<T> newList = new ArrayList<T>();
while (iterator.hasNext()) {
    newList.add(iterator.next());
return newList;
CollectionmakeCollection(final Iterator i)
make Collection
final List<T> list = new LinkedList<T>();
while (i.hasNext()) {
    list.add(i.next());
return list;
Iteratormax(final Iterator iter, final int max)
don't return more elements than given by max
return new Iterator<T>() {
    int _remaining = max;
    @Override
    public boolean hasNext() {
        return _remaining > 0 && iter.hasNext();
    @Override
    public T next() {
...
IteratormergeIterator(final Iterator iterator1, final Iterator iterator2)
merge Iterator
final Iterator<T> i1 = iterator1 != null ? iterator1 : new ArrayList<T>(0).iterator();
final Iterator<T> i2 = iterator2 != null ? iterator2 : new ArrayList<T>(0).iterator();
return new Iterator<T>() {
    private Iterator<T> it = i1;
    @Override
    public boolean hasNext() {
        return i1.hasNext() || i2.hasNext() ? true : false;
    @Override
    public T next() {
        if (this.it.hasNext() == false) {
            this.it = i2;
        return this.it.next();
    @Override
    public void remove() {
        this.it.remove();
};
booleanmoveNext(Iterator iterator)
move Next
if (iterator.hasNext()) {
    iterator.next();
    return true;
} else {
    return false;
IteratormultiIterator(Iterator... iterable)
multi Iterator
return multiIterator(Arrays.asList(iterable));
String[]multiply(String string, Iterator placeholders, Iterator replacements)
multiply
String[] result = new String[] { string };
while (placeholders.hasNext()) {
    result = multiply(result, (String) placeholders.next(), (String[]) replacements.next());
return result;
String[]multiply(String string, Iterator placeholders, Iterator replacements)
multiply
String[] result = new String[] { string };
while (placeholders.hasNext()) {
    result = multiply(result, (String) placeholders.next(), (String[]) replacements.next());
return result;
IteratormultiSetIterator(Iterator... iterable)
multi Set Iterator
return multiSetIterator(Arrays.asList(iterable));
ArrayList>nextPermutation(Iterator> it)
next Permutation
ArrayList<ArrayList<T>> resultLists = new ArrayList<ArrayList<T>>();
if (it.hasNext()) {
    Collection<T> next = it.next();
    ArrayList<ArrayList<T>> remainingLists = nextPermutation(it);
    for (T inst : next) {
        for (ArrayList<T> list : remainingLists) {
            ArrayList<T> resultList = new ArrayList<T>();
            resultLists.add(resultList);
...