Javaには複数の配列の組み合わせが可能です。

複数の配列の組み合わせを実現するには、再帰的な方法を使用することができます。具体的な手順は次の通りです:

  1. 3つのパラメーターを受け取る再帰関数を作成してください:元の配列コレクション、現在の順列結果、現在処理中の配列インデックス。
  2. 再帰関数内では、まず、処理中の配列のインデックスが元の配列の長さを超えていないかをチェックし、超えている場合は現在の並び替え結果を最終結果セットに追加します。
  3. 処理中の配列のインデックスが元の配列の長さを超えていない場合は、現在処理中の配列を取得し、その配列のすべての要素を反復処理して、各要素を現在の並び替え結果に追加します。
  4. 自身を呼び出して、現在の順列結果と次の配列インデックスを引数として渡す。
  5. 再帰関数が終了したら、最終的な結果セットを返します。

以下はコードの例です:

import java.util.ArrayList;
import java.util.List;

public class ArrayPermutation {

    public static List<List<Integer>> permute(int[][] arrays) {
        List<List<Integer>> result = new ArrayList<>();
        permuteHelper(result, new ArrayList<>(), arrays, 0);
        return result;
    }

    private static void permuteHelper(List<List<Integer>> result, List<Integer> current, int[][] arrays, int index) {
        if (index >= arrays.length) {
            result.add(new ArrayList<>(current));
            return;
        }

        int[] array = arrays[index];
        for (int i = 0; i < array.length; i++) {
            current.add(array[i]);
            permuteHelper(result, current, arrays, index + 1);
            current.remove(current.size() - 1);
        }
    }

    public static void main(String[] args) {
        int[][] arrays = {
                {1, 2, 3},
                {4, 5},
                {6, 7, 8}
        };

        List<List<Integer>> result = permute(arrays);
        for (List<Integer> list : result) {
            System.out.println(list);
        }
    }
}

結果は出力されました。

[1, 4, 6]
[1, 4, 7]
[1, 4, 8]
[1, 5, 6]
[1, 5, 7]
[1, 5, 8]
[2, 4, 6]
[2, 4, 7]
[2, 4, 8]
[2, 5, 6]
[2, 5, 7]
[2, 5, 8]
[3, 4, 6]
[3, 4, 7]
[3, 4, 8]
[3, 5, 6]
[3, 5, 7]
[3, 5, 8]

このコードは3つの配列の組み合わせを実現しています。必要に応じて元の配列セットを変更し、任意の数の配列の組み合わせを実現できます。

bannerAds