# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.misc.algorithm

## Class CartesianProduct<T>

• java.lang.Object
• com.numericalmethod.suanshu.misc.algorithm.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.
Wikipedia: n-ary product
• ### Constructor Summary

Constructors
Constructor and Description
CartesianProduct(T[]... sets)
Construct an Iterable of all combinations of arrays, taking one element from each array.
• ### Method Summary

All Methods
Modifier and Type Method and Description
Iterator<List<T>> iterator()
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface java.lang.Iterable

forEach, spliterator
• ### 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
• ### Method Detail

• #### iterator

public Iterator<List<T>> iterator()
Specified by:
iterator in interface Iterable<List<T>>