package CollectionDemo; //Java实现排列组合--递归 //参考:https://blog.csdn.net/chunrudikai/article/details/60958993?utm_source=app import java.util.ArrayList; import java.util.List;public class PailiexuheDemo {static ArrayList<String> arrayList1=new ArrayList<>();public static void main(String[] args) {String[] color = {"红", "蓝", "黑"};String[] size = {"S", "M", "L"};String[] other = {"a", "b"};List<String[]> list = new ArrayList<String[]>();list.add(color);list.add(size);list.add(other);sorting(list, color, "");for(String str:arrayList1){System.out.println(str);}}public static void sorting(List<String[]> list, String[] arrs, String str) {for (int i = 0; i < list.size(); i++) {//System.out.println(list.indexOf(arrs));//取得当前的数组if (i == list.indexOf(arrs)) {// 迭代数组for (String arr : arrs) {arr = str + arr;if (i < list.size() - 1) {arr = arr + ",";sorting(list, list.get(i + 1), arr);//System.out.println("回到了这里");} else if (i == list.size() - 1) {//System.out.println(arr);arrayList1.add(arr);}}}}}}
主要参考:参考:https://blog.csdn.net/chunrudikai/article/details/60958993?utm_source=app