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

  • SEARCH
  • Home
  • 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 7551725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:34:11+00:00 2026-05-30T10:34:11+00:00

I want to create a Java method, which accepts an inputArray = Object[n][] ,

  • 0

I want to create a Java method, which accepts an inputArray = Object[n][], where n can be any integer, and outputs a list of possible n-size combinations between all values of the n subarrays. Below is an example:

Input Array: (where Object=String and n=3)

String[] subarrayA = {"A0","A1","A2"};
String[] subarrayB = {"B0","B1"};
String[] subarrayC = {"C0","C1","C2","C3"};
String[3][] inputArray = {subarrayA, subarrayB, subarrayC};

Desired Output:

{A0,B0,C0},{A0,B0,C1},{A0,B0,C2},{A0,B0,C3},
{A0,B1,C0},{A0,B1,C1},{A0,B1,C2},{A0,B1,C3},
{A1,B0,C0},{A1,B0,C1},{A0,B0,C2},{A1,B0,C3},
{A1,B1,C0},{A1,B1,C1},{A1,B1,C2},{A1,B1,C3},
{A2,B0,C0},{A2,B0,C1},{A2,B0,C2},{A2,B0,C3},
{A2,B1,C0},{A2,B1,C1},{A2,B1,C2},{A2,B1,C3}

Obviously, I cannot have a fixed nested-loop inside my method since I do not know n in advance. So, I am guessing the only way to solve it would be through a recursive method? Any recommendations?

P.S: I am aware of the simple combination-related posts on the website.

  • 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-30T10:34:13+00:00Added an answer on May 30, 2026 at 10:34 am

    This should solve your problem.

    public static void permute(String array[][], int index, ArrayList<String> output){
    
        if(index == array.length){
            System.out.println(output.toString());
        }
        else{
            for(int i=0 ; i<array[index].length ; i++){
                output.add(array[index][i]);
                permute(array,index+1,output);
                output.remove(output.size() - 1); 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried to create a web method which has parameter of java.lang.Object but I
I want to create a sample RESTful web service in java which involves all
I have an activity which shows an image (ViewCollection.java). I want to only create
Background Currently, if I want to create a new object in C# or Java,
I want to create a Java application bundle for Mac without using Mac. According
I want to create a Java Desktop Application and want to employ some mechanism
I want create a excel with Apache POI in java and I must insert
I want to create registry key through java program to add the jar file
I want to create a simple bash script to launch a Java program on
I want to create a purpose built device capable of running a java vm

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.