代码:
List<String[]> list = new ArrayList<String[]>();
String[] str = new String[1];
str[0] = "a1";
list.add(str);
str = new String[3];
str[0] = ",b1";
str[1] = ",b2";
str[2] = ",b3";
list.add(str);
str = new String[2];
str[0] = ",c1";
str[1] = ",c2";
list.add(str);
str = new String[2];
str[0] = ",e1";
str[1] = ",e2";
list.add(str);
str = new String[4];
str[0] = ",d1";
str[1] = ",d2";
str[2] = ",d3";
str[3] = ",d4";
list.add(str);
我想的到所有组合的结果,不过每个数据的下标不能变
就好比:
不知道你的1是什么意思
public void listString(list,index){
if(index == list.size()){
System.out.println();
}
String[] s = list.get(index);
for(int i = 0; i < s.length(); i++){
if(index == 0){
System.out.print(s[i]);
}
else{
System.out.print("," + s[i]);
}
listString(list,index+1);
}
}
import java.util.*;
public class FullPermutation
{
public static void main(String[] args)
{
System.out.println("Hello World!");
List<String[]> list = new ArrayList<String[]>();
String[] str = new String[1];
str[0] = "a1";
list.add(str);
str = new String[3];
str[0] = "b1";
str[1] = "b2";
str[2] = "b3";
list.add(str);
str = new String[2];
str[0] = "c1";
str[1] = "c2";
list.add(str);
str = new String[2];
str[0] = "e1";
str[1] = "e2";
list.add(str);
str = new String[4];
str[0] = "d1";
str[1] = "d2";
str[2] = "d3";
str[3] = "d4";
list.add(str);
for(String[] s : list){
System.out.println(Arrays.toString(s));
}
System.out.println("--------------");
fullPermutation(list,0,null);
}
public static void fullPermutation(List<String[]> list,int index,List<String> result){
if(index == list.size()){
System.out.println(result);
return;
}
String[] s = list.get(index);
for(int i = 0; i < s.length; i++){
if(index == 0){
result = new ArrayList<String>();
result.add(s[i]);
}
else{
result.add(s[i]);
}
fullPermutation(list,index + 1,result);
result.remove(s[i]);
}
}
}