3

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);
  • Besides looking into that "ready to go code" from the aforementioned duplicate question ... you might want to google for "permute lists" and maybe try to implement it yourself. It isn't too difficult; and you learn much more from doing such things yourself. Besides; actually, your question isn't too good. You merely wrote down your requirements; but your own code stops right there, were things get interesting. Too a certain degree, this looks like you want to dump the **work** part of your homework on other people. – GhostCat May 31 '16 at 09:05

0 Answers0