How do I generate a Cartesian product in Java?

前端 未结 5 1097
予麋鹿
予麋鹿 2020-12-16 19:13

I have a number of ArrayList with each ArrayList having objects and each one can have different length. I need to generate permutation like in the

5条回答
  •  情书的邮戳
    2020-12-16 19:57

    Use nested for loops that would have a loop for every ArrayList as below. I am assuming I have two ArrayLists - intList and stringList. I can have two nested for loops (one for each list) to generate the permutation.

        for(Integer i : intList){
            for (String s : stringList) {
                ...
            }
        }
    

提交回复
热议问题