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 6650969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:57:18+00:00 2026-05-26T00:57:18+00:00

I have a List of List<String> ‘s which I get from a external API

  • 0

I have a List of List<String>‘s which I get from a external API method call:

List<List<String>> outerList

I have to create unique key combinations by concatenating strings from each list in the same order they are in the outer list.

Example: If outer list has 2 inner lists, say list1: {“A”,”B”} and list2: {“C”,”D”}. Then possible unique combinations will be AC, AD, BC and BD.

But the problem is the outerList size is dynamic, it can contain any number of inner lists. If the inner list numbers are fixed then I can write for loops and create combinations.

I am thinking in the direction of using reflections, recursion etc but so far have not been able to solve it.

public static void main(String[] args) {

    List<List<String>> outerList = new ArrayList<List<String>>();
    List<String> list1 = new ArrayList<String>();
    list1.add("A");
    list1.add("B");
    List<String> list2 = new ArrayList<String>();

    list2.add("C");
    list2.add("D");
    outerList.add(list1);

    outerList.add(list2);

    for(String s1: list1) {
        for(String s2: list2) {
            System.out.println(s1+s2);
        }
    }
}

Here outerList has 2 inner lists so I have created 2 for loops explicitly to iterate and concatenate. But in real-time outerList can have any number of inner lists, how to loop dynamically loop through all the inner loops and concatenate?

  • 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-26T00:57:19+00:00Added an answer on May 26, 2026 at 12:57 am

    This code works for me:

    public class Test
    {  
    
        public static void generate(LinkedList<LinkedList<String>> outerList, String outPut) {
            LinkedList<String> list = outerList.get(0);
    
            for(String str : list) {
                LinkedList<LinkedList<String>> newOuter = new LinkedList<LinkedList<String>>(outerList);
                newOuter.remove(list);
    
                if(outerList.size() > 1) {
                    generate(newOuter, outPut+str);
                 } else {
                   System.out.println(outPut+str);
                 }
            }
        }
    
        public static void main(String[] args) 
        {
            LinkedList<LinkedList<String>> outerList = new LinkedList<LinkedList<String>>();
    
            LinkedList<String> list1 = new LinkedList<String>();
            LinkedList<String> list2 = new LinkedList<String>();
    
            list1.add("A");
            list1.add("B");
    
            list2.add("C");
            list2.add("D");
    
            outerList.add(list1);
            outerList.add(list2);
    
            Test.generate(outerList, "");
        }      
    }
    

    Output:

    AC
    AD
    BC
    BD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASMX web service which has a method - void DoSomething(List<string> list);
If I have List<String> text how can I create a sub-list of all continious
I have a List(Of String) which corresponds to types on our database table. We
I have a list of strings (a List<String> ) that can have anywhere from
I have a list in a string, as below (from a <textarea> element with
I have a list of string, which is most likely, but not guaranteed to
I have a List of string objects which represent process names. I want to
I have a string list to be used with the AccuWeather API that is
I have a list of String which I wish to convert to Json. I
I have a list string tag. I am trying to initialize a dictionary with

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.