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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:06:00+00:00 2026-05-25T20:06:00+00:00

I have many Arraylists having String objects , and I have a requirement to

  • 0

I have many Arraylists having String objects , and I have a requirement to concatenate there values.
Eg:

ArrayList finalList = new ArrayList();
ArrayList catMe = new ArrayList();
ArrayList x = new ArrayList();
x.add("Green");
x.add("Red");
ArrayList y = new ArrayList();
y.add(" Apple");

//......

catMe.add(x);
catMe.add(y);

concatContents(catMe);  // Here i need to do 
                        // some concatenation magic.

so when finalList is printed:

finalList.get(0) // should show > "Green Apple"
finalList.get(1) // should show >  "Red Apple"

I know it looks easy if there are only two list X and Y… but I need it for n dimensions. Say if there is 3rd list

ArrayList z= new ArrayList();
z.add(" USA");
z.add(" Canada");
catMe.add(z);
concatContents(catMe);

Now finalList should show

Green Apple USA
Green Apple Canada
Red Apple USA
Red Apple Canada

Do i need recursion? Unable to think how to implement though! Do any java master there have a solution?

  • 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-25T20:06:00+00:00Added an answer on May 25, 2026 at 8:06 pm

    Here’s a recursive answer. Just cooked it up, so no guarantees on quality… 🙂

    public ArrayList<String> concatLists(ArrayList<ArrayList<String>> list) {
        ArrayList<String> catStrs = new ArrayList<String>();
        int len = list.size();
        if (len == 1) {
            catStrs.addAll(list.get(0));
            return catStrs;
        }
        ArrayList<String> myStrs = list.get(0);
        ArrayList<ArrayList<String>> strs = new ArrayList<ArrayList<String>>();
        strs.addAll(list.subList(1, len));
        ArrayList<String> retStrs = concatLists(strs);
        for (String str : myStrs) {
            for (String retStr : retStrs) {
                catStrs.add(str+retStr);
            }
        }
        return catStrs;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects like this: ArrayList<Phone> list = new ArrayList(); list.add(new
i have a hashmap where every key has many values(stored in a arraylist). How
See the following ArrayList: List<Integer> values = new ArrayList<Integer>(); values.add(0); values.add(1); values.add(2); values.add(3); values.add(4);
I have classes: class User{ String id; ArrayList<UserAttribute> attributeList=new ArrayList<UserAttribute>(); } class UserAttribute{ User
I have ArrayLists that store many objects, and objects are frequently added and removed
C++ has std::vector and Java has ArrayList , and many other languages have their
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i <
Let's say I have two same strings inside an ArrayList... is there a way
one problem I'm having is i have 2 JTextAreas and i need to add
I have an ArrayList which contains duplicate values at diff diff index. for example

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.