I have an string array
{"ted", "williams", "golden", "voice", "radio"}
and I want all possible combinations of these keywords in the following form:
{"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",
.... }
I've been going for hours with no effective result (side effect of high-level programming ??).
I know the solution should be obvious but I'm stuck, honestly ! Solutions in Java/C# are accepted.
EDIT:
- It's not a homework
- "ted williams" and "williams ted" are considered the same, so I want "ted williams" only
EDIT 2: after reviewing the link in the answer, it turns out that Guava users can have the powerset method in com.google.common.collect.Sets
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…