I want to generate an array which content would represent a Cartesian product of the two given string-arrays. In other words, I need to concatenate each String from the first array arr1 with every String from the second array arr2. Here is my code: Current Output: Desired Output: How can I fix it? Answer You don’t need the very first

# Tag: cartesian-product

## How to get Cartesian product from multiple lists?

Say I have several List<T>s, I will put them into another list or other collections, so I don’t know how many list<T> I have until I call List<List<T>>.size() Take below List<Integer> as an example: How can I get the result of list1*list2*list3*…listn as a Cartesian product? For example: should be: Answer You can use recursion to achieve it, your base

## Iteratively compute the Cartesian product of an arbitrary number of sets

I want to compute the cartesian product of an arbitrary number of nonempty sets in Java. I’ve wrote that iterative code… public static List<Set> cartesianProduct(List<…