Here you can find the source of multiIterator(Iterator extends X>... iterable)
public static <X> Iterator<X> multiIterator(Iterator<? extends X>... iterable)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; public class Main { public static <X> Iterator<X> multiIterator(Iterator<? extends X>... iterable) { return multiIterator(Arrays.asList(iterable)); }// w w w. j av a 2 s . co m public static <X> Iterator<X> multiIterator(Iterator<? extends Iterator<? extends X>> iterable) { return new Iterator<X>() { Iterator<? extends X> curIter = null; @Override public boolean hasNext() { while ((curIter == null || !curIter.hasNext()) && iterable.hasNext()) { while (iterable.hasNext()) { curIter = iterable.next(); break; } } return curIter != null && curIter.hasNext(); } @Override public X next() { if (curIter == null) { throw new NoSuchElementException(); } return curIter.next(); } }; } public static <X> Iterator<X> multiIterator(Iterable<? extends Iterator<? extends X>> iterable) { return multiIterator(iterable.iterator()); } }