package ru.job4j.collections;

import java.util.*;


/**
 * Created by admin on 11.05.2017.
 */
public class ConvertList {
    /**
     *  toList.
     * @param array
     * @return list
     */
    public List<Integer> toList(int[][] array) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            for (int j =0; j <array[0].length; j++) {
                list.add(array[i][j]);
            }
        }
        return list;
    }

    /**
     * toArray.
     * @param list
     * @param rows
     * @return arrayInt
     */
    public int[][] toArray(List<Integer> list, int rows) {
        ArrayList<Integer> arrayList = (ArrayList) list;
        arrayList.trimToSize();
        int size = arrayList.size() <= rows ? 1 : arrayList.size() % rows == 0 ? arrayList.size() / rows : arrayList.size() / rows + 1;
        int[][] arrayInt = new int[rows][size];
        System.out.println(size);
        Iterator<Integer> iterator = arrayList.iterator();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < size; j++) {
                if (iterator.hasNext()) {
                    arrayInt[i][j] = iterator.next();
                }
            }
        }
        return arrayInt;
    }
    /**
     * convert.
     * @param list
     * @return
     */
    public List<Integer> convert (List<int[]> list) {
        LinkedList<int[]> tempList =  (LinkedList) list;
        List<Integer> allLists = new LinkedList<>();
        for (int i = 0; i < tempList.size(); i++ ) {
            for (int j = 0; j < tempList.get(i).length; j++) {
                allLists.add(Integer.valueOf(list.get(i)[j]));
            }
        }
        return allLists;
    }
}

@@ -1503,104 +1503,63 @@
 (int
- i = 0; i %3C tempList.size(); i++ ) %7B%0A            for (int j = 0; j %3C tempList.get(i).length; j++
+%5B%5D temp : tempList) %7B%0A            for (int temp2 : temp
 ) %7B%0A
@@ -1607,22 +1607,13 @@
 eOf(
-list.get(i)%5Bj%5D
+temp2
 ));%0A

task 10037