Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4019738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:08:31+00:00 2026-05-20T10:08:31+00:00

I have an string array {ted, williams, golden, voice, radio} and I want all

  • 0

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:

  1. It’s not a homework
  2. “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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:08:32+00:00Added an answer on May 20, 2026 at 10:08 am

    EDIT: As FearUs pointed out, a better solution is to use Guava’s Sets.powerset(Set set).

    EDIT 2: Updated links.


    Quick and dirty translation of this solution:

    public static void main(String[] args) {
    
        List<List<String>> powerSet = new LinkedList<List<String>>();
    
        for (int i = 1; i <= args.length; i++)
            powerSet.addAll(combination(Arrays.asList(args), i));
    
        System.out.println(powerSet);
    }
    
    public static <T> List<List<T>> combination(List<T> values, int size) {
    
        if (0 == size) {
            return Collections.singletonList(Collections.<T> emptyList());
        }
    
        if (values.isEmpty()) {
            return Collections.emptyList();
        }
    
        List<List<T>> combination = new LinkedList<List<T>>();
    
        T actual = values.iterator().next();
    
        List<T> subSet = new LinkedList<T>(values);
        subSet.remove(actual);
    
        List<List<T>> subSetCombination = combination(subSet, size - 1);
    
        for (List<T> set : subSetCombination) {
            List<T> newSet = new LinkedList<T>(set);
            newSet.add(0, actual);
            combination.add(newSet);
        }
    
        combination.addAll(combination(subSet, size));
    
        return combination;
    }
    

    Test:

    $ java PowerSet ted williams golden
    [[ted], [williams], [golden], [ted, williams], [ted, golden], [williams, golden], [ted, williams, golden]]
    $
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Non repeating random number array I have a String array with many
I have a string array as: String[] guaranteedOutput = Arrays.copyOf(values, values.length, String[].class); All the
I have a String array which I want to convert to specifc format. For
I have a string array. What is the simplest way to check if all
I have string array [1, 2, 3] and i search for all of those
I have string array str[10][3] , it is full of values. Now I want
I Have a string array with 5 values, i want the program to loop
i have a string array consisting of a name and a score. I want
I have a String array with the following values: dim strArray() as string dim
I have a string array Array1 and a string array A2. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.