Finding cartesian product in Java(在 Java 中查找笛卡尔积)
问题描述
我想找到一组元素的笛卡尔积.这是一个例子
I want to find cartesian product of set of elements. Here's an example
示例 1:
sets : (ab) (bc) (ca)
笛卡尔积是:
abc aba acc aca bbc bba bcc bca
示例 2:
sets : (zyx) b c
笛卡尔积是:
zbc ybc xbc
所以我正在考虑一种在 Java 中执行的算法,它可以在开始时找到在编译时定义的特定数量组的笛卡尔积.
So I am thinking of an algorithm to execute in Java which can find cartesian product of particular amount of groups defined at compile time at the start.
推荐答案
您可以使用 Sets.cartesianProduct()
方法来自 Google 的 Guava 库 用于生成笛卡尔积:
You can use the Sets.cartesianProduct()
method from Google's Guava libraries to generate Cartesian products:
com.google.common.collect.Sets.cartesianProduct(Set[] yourSets)
要是一切都这么简单就好了!
If only everything was that easy!
这篇关于在 Java 中查找笛卡尔积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Java 中查找笛卡尔积


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01