Class CartesianProduct<T>

  • All Implemented Interfaces:
    Iterable<List<T>>

    public class CartesianProduct<T>
    extends Object
    implements Iterable<List<T>>
    The Cartesian product can be generalized to the n-ary Cartesian product over n sets X1, ..., Xn. \[ X_1\times\cdots\times X_n = \{(x_1, \ldots, x_n): x_i \in X_i \} \] It is a set of n-tuples.
    See Also:
    Wikipedia: n-ary product
    • Constructor Detail

      • CartesianProduct

        public CartesianProduct​(T[]... sets)
        Construct an Iterable of all combinations of arrays, taking one element from each array.

        For example, suppose we have two arrays:

         {1, 2}
         {3, 4, 5}
         
        The possible combinations are:
         {1, 3}
         {1, 4}
         {1, 5}
         {2, 3}
         {2, 4}
         {2, 5}
         
        Parameters:
        sets - arrays of elements