在java中,谁有好的算法可以将多个list进行组合?
比如有N个list:listA={a,b,c}listB={d,e,f}listc={x,y,z}......listn={j,k,l}要将几个list的内容进行组合结果...
比如有 N个list: list A = {a,b,c} list B = {d,e,f} list c = {x,y,z} ...... list n = {j,k,l}
要将几个list的内容进行组合 结果为 adx...j,ady...j,adz....j,aex..j,aey..j ....依次类推
注意 只要组合 不排列 展开
要将几个list的内容进行组合 结果为 adx...j,ady...j,adz....j,aex..j,aey..j ....依次类推
注意 只要组合 不排列 展开
1个回答
推荐于2016-01-04
展开全部
// 回答完毕,采纳即可
import java.util.Arrays;
import java.util.LinkedList;
public class TT
{
private static LinkedList<String[]> recursionSub ( LinkedList<String[]> list, int count, String[][] array, int ind,
int start, int... indexs )
{
start++;
if (start > count - 1)
{
return null;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs[start] = 0; indexs[start] < array[start].length; indexs[start]++ )
{
recursionSub (list, count, array, 0, start, indexs);
if (start == count - 1)
{
String[] temp = new String[count];
for ( int i = count - 1; i >= 0; i-- )
{
temp[start - i] = array[start - i][indexs[start - i]];
}
list.add (temp);
}
}
return list;
}
public static void main ( String[] args )
{
String[] s1 = { "a", "b", "c" };
String[] s2 = { "d", "e", "f" };
String[] s3 = { "x", "y", "z" };
String[][] temp = { s1, s2, s3 };
LinkedList<String[]> list = new LinkedList<String[]> ();
recursionSub (list, temp.length, temp, 0, -1);
for ( int i = 0; i < list.size (); i++ )
{
System.out.println (Arrays.toString (list.get (i)).replaceAll ("[\\[\\]\\,\\s]", ""));
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询