ConvertIterator implements  Converter<Integer> { @Override public Iterator<Integer> convert(final Iterator<Iterator<Integer>> it) { return new Iterator<Integer>() { private Iterator<Iterator<Integer>> bigBox = it; private Iterator<Integer> box = null; @Override public boolean hasNext() { boolean result = false; if(bigBox.hasNext() || (box != null && box.hasNext())){ result = true; } return result; } @Override public Integer next() { Integer result; if((box == null || !box.hasNext()) && bigBox.hasNext() ){ box = bigBox.next(); } if(box.hasNext()){ result = box.next(); } else{ throw new NoSuchElementException(); } return result; } @Override public void remove() { } }; }  @Override Iterator<Integer> convert(final Iterator<Iterator<Integer>> it);  }
@Test public void whenConvertDataFromIteratorIteratorovThatGetSimpleIterator(){ ArrayList<Integer> one = new ArrayList<>(Arrays.asList(4,2,0,4,6,4,9)); ArrayList<Integer> two = new ArrayList<>(Arrays.asList(0,9,8,7,5)); ArrayList<Integer> three = new ArrayList<>(Arrays.asList(1,3,5,6,7,0,9,8,4)); ArrayList<Iterator<Integer>> bigBox = new ArrayList<>(Arrays.asList(one.iterator(),two.iterator(),three.iterator())); ConvertIterator converter = new ConvertIterator(); Iterator<Integer> it = converter.convert(bigBox.iterator()); int[] control = {4,2,0,4,6,4,9,0,9,8,7,5,1,3,5,6,7,0,9,8,4}; int[] result = new int[21]; int position = 0; while(it.hasNext()){ result[position++] = it.next(); } Assert.assertThat(result,is(control)); }