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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:11:14+00:00 2026-05-23T16:11:14+00:00

So for my current program, I am currently doing this: Java Code ArrayList<Section> aMainSection

  • 0

So for my current program, I am currently doing this:

Java Code

        ArrayList<Section> aMainSection = new ArrayList<Section>();
        Section aSection = new Section();
        aSection.setName("Document 1");
        aSection.setSection("Section 1");
        aSection.setText("Text 1");
        Section aSection2 = new Section();
        aSection2.setName("Document 2");
        aSection2.setSection("Section 2");
        aSection2.setText("Text 2");
        Section aSection3 = new Section();
        aSection3.setName("Document 3");
        aSection3.setSection("Section 3");
        aSection3.setText("Text 3");

But what I want to be able to do is create a for loop in which when the condition is met, I can just create a new Section. However, I do not know how to increment variables in Java. I would assume it should be possible, somehow, but I know it’s not as simple as concatenating an integer value to the end of the variable name. Any help would be appreciated, thank you.

  • 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-23T16:11:15+00:00Added an answer on May 23, 2026 at 4:11 pm

    Sounds like you want to do this:

    ArrayList<Section> aMainSection = new ArrayList<Section>();
    for(int i = 0; i < 3; i++)
    {
        Section aSection = new Section();
        aSection.setName("Document "+(i+1));
        aSection.setSection("Section "+(i+1));
        aSection.setText("Text "+(i+1));
        aMainSection.Add(aSection);
    }
    

    If you don’t know how many times you want to do it before hand try this:

    ArrayList<Section> aMainSection = new ArrayList<Section>();
    int sectionNumber = 1;
    boolean done = false;
    while(!done)
    {
        Section aSection = new Section();
        aSection.setName("Document "+ sectionNumber);
        aSection.setSection("Section "+ sectionNumber);
        aSection.setText("Text "+ sectionNumber);
        aMainSection.Add(aSection);
    
        sectionNumber++;
        done = <put something interesting here>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://img136.imageshack.us/img136/3508/texturefailz.png This is my current program. I know it's terribly ugly, I found two
How can I change the current working directory from within a Java program? Everything
Take this code: using System; namespace OddThrow { class Program { static void Main(string[]
I'm currently working with Java to write a program that does an EAI between
I am writing an updater. I have this code: package main; import java.io.*; import
My current program need to use programatically create a XPathExpression instance to apply to
I need to use the current library name explicitly in a CL program. CHGVAR
I am trying to get the program to call up the current date, add
Using my c++ program how can I find out what group the current user
How can I avoid that a user starts the same program twice? The current

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.