数组的所有可能组合
我有一个字符串数组
{"ted", "williams", "golden", "voice", "radio"}
我想要这些关键字的所有可能组合,如下所示:
{"ted",
"williams",
"golden",
"voice",
"radio",
"ted williams",
"ted golden",
"ted voice",
"ted radio",
"williams golden",
"williams voice",
"williams radio",
"golden voice",
"golden radio",
"voice radio",
"ted williams golden",
"ted williams voice",
"ted williams radio",
.... }
我已经花了几个小时没有有效的结果(高级编程的副作用??)。
我知道解决方案应该是显而易见的,但老实说,我被困住了!接受 Java/C# 中的解决方案。
编辑:
- 这不是家庭作业
- “ted williams”和“williams ted”被认为是一样的,所以我只想要“ted williams”
编辑2:在查看了答案中的链接后,事实证明,番石榴用户可以在com.google.common.collect.Sets中使用powerset方法。