As an example. Suppose there are 2 types of fruits (apple and orange) at a grocery store, and you want to buy 3 pieces of fruit. You could select
Generate 3-combinations with repetitions of the set (apple, orange).
// Create the initial vector of (apple, orange) ICombinatoricsVector<String> initialVector = Factory.createVector(new String[] { "apple", "orange" }); // Create a multi-combination generator to generate 3-combinations of // the initial vector Generator<String> gen = Factory.createMultiCombinationGenerator(initialVector,3); // Print all possible combinations for (ICombinatoricsVector<String> combination : gen) { System.out.println(combination); }
And the result of 4 multi-combinations
CombinatoricsVector=([apple, apple, apple], size=3) CombinatoricsVector=([apple, apple, orange], size=3) CombinatoricsVector=([apple, orange, orange], size=3) CombinatoricsVector=([orange, orange, orange], size=3)