Suppose you have an unbound list of named arrays:
ArrayNode[] vertexes = new ArrayNode[] {
new ArrayNode("nouns", new String[]{"John", "Mary"}),
new ArrayNode("verbs", new String[]{"Eats", "Works", "Plays"}),
new ArrayNode("objects", new String[]{"Food", "Computer", "Guitar"})
};
Given an order to follow, say "nouns->verbs->objects", what algorithm can we use to associate all elements of the arrays in the given order? The output is something like the following:
["John Eats Food"], ["John Eats Computer"], ["John Eats Guitar"],
["John Works Food"], ["John Works Computer"], ["John Works Guitar"],
..., ..., ...,
..., ["Mary Plays Computer"], ["Mary Plays Guitar"]
The number of arrays is unbound and the sequence can be any for the given number of arrays.
Solution
Using Java 8 and Google Guava 19 Lists.cartesianProduct Take a look at the answer to this at Iterative Cartesian Product in Java