Here you can find the source of combineArray(List> data)
public static List<List<String>> combineArray(List<List<String>> data)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static List<List<String>> combineArray(List<List<String>> data) { List<List<String>> columns = new ArrayList<>(); calculation(data, columns);//from w ww. j a v a2 s .co m List<String> column = columns.get(0); List<List<String>> groups = new ArrayList<>(); for (int i = 0; i < column.size(); i++) { List<String> group = new ArrayList<String>(); group.add(column.get(i)); for (int j = 0 + 1; j < columns.size(); j++) { List<String> values = columns.get(j); group.add(values.get(i % values.size())); } groups.add(group); } return groups; } private static void calculation(List<List<String>> data, List<List<String>> columns) { List<String> column = new ArrayList<>(); int k = columns.size(); for (int i = 0; i < data.get(k).size(); i++) { int times = 1; for (int j = k + 1; j < data.size(); j++) { int valCount = data.get(j).size(); times = times * valCount; } for (int j = 0; j < times; j++) { column.add(data.get(k).get(i)); } } columns.add(column); if (data.size() > columns.size()) { calculation(data, columns); } } }