@@ -0,0 +1,1868 @@
+package Iterator;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0A/**%0A * Created by user8.3 on 30.05.2017.%0A */%0Apublic class IteratorIterator %7B%0A    public static void main(String%5B%5D args) %7B%0A        Iterator%3CInteger%3E first = Arrays.asList(1, 2, 3).iterator();%0A        Iterator%3CInteger%3E second = Arrays.asList(4, 5, 6).iterator();%0A        Iterator%3CIterator%3CInteger%3E%3E it = Arrays.asList(first, second).iterator();%0A        Iterator%3CInteger%3E iter = convert(it);%0A        while (iter.hasNext()) %7B%0A            System.out.println(iter.next());%0A        %7D%0A    %7D%0A%0A    private static Iterator%3CInteger%3E convert(Iterator%3CIterator%3CInteger%3E%3E it) %7B%0A        It iterator = new It(it);%0A        int j= 0;%0A        return iterator;%0A    %7D%0A    public static class It implements Iterator %7B%0A        private Iterator%3CIterator%3CInteger%3E%3E list;%0A        private ArrayList%3CIterator%3CInteger%3E%3E arrayList = new ArrayList%3C%3E();%0A        int index = 0;%0A%0A        public It(Iterator%3CIterator%3CInteger%3E%3E list) %7B%0A            this.list = list;%0A            while (list.hasNext()) %7B%0A                arrayList.add(list.next());%0A            %7D%0A        %7D%0A%0A        @Override%0A        public boolean hasNext() %7B%0A            if (index %3C arrayList.size()) %7B%0A                if (arrayList.get(index).hasNext()) %7B%0A                    return true;%0A                %7D else %7B%0A                    if (index + 1 %3C arrayList.size()) %7B%0A                        return true;%0A                    %7D%0A                %7D%0A            %7D%0A            return false;%0A        %7D%0A%0A        @Override%0A        public Object next() %7B%0A            if (arrayList.get(index).hasNext()) %7B%0A                return arrayList.get(index).next();%0A            %7D else %7B%0A                return arrayList.get(++index).next();%0A            %7D%0A        %7D%0A%0A        @Override%0A        public void remove() %7B%0A        %7D%0A    %7D%0A%7D

task 151