import java.util.*;
public class lISTSS {
public static <t> void getCombination(List<t>... lists) {
if (lists == null) return;
getCombinations(new ArrayList<t>(), 0, lists);
}
private static <t> void getCombinations(List<t> soFar, int i, List<t>... lists) {
if (i == lists.length) { //no more lists left:
System.out.println(soFar);
} else {
for (T t : lists[i]) {
soFar.add(t); //"guess" item
getCombinations(soFar, i + 1, lists); //recurse on rest of lists
soFar.remove(soFar.size() - 1); //cleanup
}
}
}
public static void main(String args[]) {
List<string> A = Arrays.asList("one","two","three");
List<string> B = Arrays.asList("four","five");
getCombination(A,B);
}
}
What I have tried:
This is the current output:
[one, four]
[one, five]
[two, four]
[two, five]
[three, four]
[three, five]
I have the above code that gets all combinations of two lists, and I got the output, but I want to remove the combinations [one, five] and [two, four]. I've tried the following without avail.
if(soFar.get(i).equals("one, five")) {
soFar.remove("one, five");
}