Java笛卡尔积集合

Java笛卡尔积集合,java,collections,product,cartesian,Java,Collections,Product,Cartesian,我需要做3个列表中的笛卡尔积。 这是代码 XList<T> combine() { XList<T> returnList = new XList<>(); List<T> list = new ArrayList(this.coll); List<T> a = (List<T>) list.get(0); List<T> b = (List<T>) list.ge

我需要做3个列表中的笛卡尔积。 这是代码

 XList<T> combine() {
    XList<T> returnList = new XList<>();

    List<T> list = new ArrayList(this.coll);
    List<T> a = (List<T>) list.get(0);
    List<T> b = (List<T>) list.get(1);
    List<T> c = (List<T>) list.get(2);

    //working
    //List<XList<T>> ll2 = a.stream().flatMap(ai -> b.stream().map(bi -> new XList<>(Arrays.asList(ai, bi)))).collect(Collectors.toList());

    // not working
    List<XList<T>> ll3 = a.stream().flatMap(ai -> b.stream().flatMap(bi -> c.stream().map(ci -> new XList<>(Arrays.asList(ai, bi, ci))))).collect(Collectors.toList());


    returnList.coll = (Collection<T>) ll3;

    return returnList;
}
XList combine(){
XList returnList=new XList();
List List=新的ArrayList(this.coll);
List a=(List)List.get(0);
listb=(List)List.get(1);
List c=(List)List.get(2);
//工作
//List ll2=a.stream().flatMap(ai->b.stream().map(bi->new XList(Arrays.asList(ai,bi))).collect(Collectors.toList());
//不起作用
List ll3=a.stream().flatMap(ai->b.stream().flatMap(bi->c.stream().map(ci->new XList(Arrays.asList(ai,bi,ci‘‘)’)).collect(Collectors.toList());
returnList.coll=(集合)ll3;
退货清单;
}
当我尝试从列表a和b做笛卡尔积时,它是有效的,但如果我想用a、b和c做,它会重新运行空列表。怎么了?
感谢您的回复。

最好使用现有的解决方案,例如


作为替代,您可以使用此库

我想我不能使用其他库。
如果有人有什么想法,我将非常感谢。

两个示例都给出了预期的输出。但是我使用了标准的ArrayList,我不知道在您的代码片段中什么是
XList
。我认为您需要在
XList
中正确识别问题;真奇怪。你确定ll3给出了这样的预期输出[[a,X,1],[b,X,1],[a,Y,1],[a,Z,1],[b,Z,1],[a,X,2],[b,X,2],[a,Y,2],[a,Z,2]?列表ll3仍然为我返回一个空列表。List ll3=a.stream().flatMap(ai->b.stream().flatMap(bi->c.stream().map(ci->new XList(Arrays.asList(ai,bi,ci‘‘‘)’)).collect(Collectors.toList())XList是一个扩展ArrayList的类。您能提供完整的最小示例来重现吗?包括
XList
?我可以将代码发送到电子邮件吗?