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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:52:18+00:00 2026-05-28T02:52:18+00:00

I am using a for loop to iterate through a list of arrays that

  • 0

I am using a for loop to iterate through a list of arrays that all have the same name expect a different number at the end. For example child1, child2, etc. I though if I tried childi where i is the variable that I would be able to loop through all the arrays. However, that did not work. I have change i from an int to a string and concatenating it on the end, but then I get a new variable that is not the same at the array. Any ideas.

        int i=0;
        String []child=childi;//so child would refer to child0 then child1
        for (int j = 0; j < child.length(); j++) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            children.add(curChildMap);
            curChildMap.put(NAME, child[j]);
            curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
        }   
         i++
  • 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-28T02:52:19+00:00Added an answer on May 28, 2026 at 2:52 am

    You cannot reference a variable by a dynamically computed name. In this case your best bet is probably to create an array or other container to hold your child arrays. For example,

    String[][] children = new String[][] { child0, child1, child2, child3, /* ... */ };
    for (int i = 0; i < children.length; i++) {
      String[] child = children[i];
      for (int j = 0; j < child.length(); j++) {
        Map<String, String> curChildMap = new HashMap<String, String>();
        children.add(curChildMap);
        curChildMap.put(NAME, child[j]);
        curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
      }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have referred to the following question at: Using foreach loop to iterate through
I have the same code running against two different SharePoint installations, to iterate through
I am using a while loop to iterate through a cursor and then outputing
I would like to iterate through all elements in an std::list in parallel fashion
I am trying to use a for next loop to iterate through the arrays
Is there a way to iterate ValueCollection using straight for loop? (not foreach) e.g.
How can I iterate over each file in a directory using a for loop?
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
Is there any way to clean up this type of loop using LINQ? List<Car>
If I have a list of ID's that I have selected from a statement

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.