I have a list of lists:
[[a, b], [X, Y, Z], [1, 2]]
I want to achieve this combination:
[[a, X, 1], [b, X, 1], [a, Y, 1], [b, Y, 1], [a, Z, 1], [b, Z, 1], [a, X, 2], [b, X, 2], [a, Y, 2], [b, Y, 2], [a, Z, 2], [b, Z, 2]]
Can anyone help me achieve this, because i run out of ideas and dont know how to do this. I know that I should use recursion. This is my code:
public XList<XList<T>> combine() {
XList<XList<T>> tmp = (XList<XList<T>>) this;
for (XList<T> lst : tmp){
}
return null;
}
XList
is a class that extedns ArrayList
and implements Set
. This fragment of code that i use to check this method:
List<String> sa = Arrays.asList( "a", "b");
List<String> sb = Arrays.asList( "X", "Y", "Z" );
XList<String> sc = XList.charsOf( "12" );
XList toCombine = XList.of(sa, sb, sc);
System.out.println(toCombine);
XList<XList<String>> cres = toCombine.combine();
System.out.println(cres);