Java List Combine combineArray(List> data)

Here you can find the source of combineArray(List> data)

Description

combine Array

License

Apache License

Declaration

public static List<List<String>> combineArray(List<List<String>> data) 

Method Source Code


//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);
        }
    }
}

Related

  1. combine(List a, List b)
  2. combine(List dest, Collection... src)
  3. combine(List list, int maxK)
  4. combine(List... dests)
  5. combineAfterIndexWithQuotes(List commands, String match)
  6. combineArray(List... p)
  7. combineAsLists(Object one, Object two)
  8. combineAux(List> collections, List objectAccumulator, List> resultList)
  9. combineFloat(List nums)