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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:09:45+00:00 2026-05-28T04:09:45+00:00

I’m trying to generate a variable number of arrayLists with a variable number of

  • 0

I’m trying to generate a variable number of arrayLists with a variable number of items within the list. This means that I can’t use an array instead of an arrayList.

When generating a JLabel in an array, you use the for loop and say:

 label[i]=new JLabel();

Is this possible for an arrayList?

I can’t put up my code because it’s to long but i’ll give you the general idea: Within a txt, there are multiple objects, in this case, troops: longbowman, man at arms, knight… Each 1 shares the same stats (ArrayLists) but have different values for each one. I have it so that once the bufferedReader finishes with a troop, it sends all the arraylists to another class, and continues reading and overwriting the old troops stats (they are now stored in a different class). the problem is, how can the other class differentiate between the stats? This would be easy if the number of types of troops was constant, but, it isn’t. So how can I do this?

Edit: here is a bit of the source code:

while ((text = reader.readLine()) != null) {
            StringTokenizer troops = new StringTokenizer(text, "=");
            String list = troops.nextToken();
            String value = troops.nextToken();

            else if (list.equals("Done")) {
                troop trooper=new troop();
                trooper.troopLoaded(kingdom,lord,troop,troopAmount,weapon,animal);

}

/////

troop class:

   public void troopLoaded(ArrayList<String> kingdom,ArrayList<String> lord,ArrayList<String> troop,ArrayList<String>,troopAmount,ArrayList<String> weapon,ArrayList<String> animal) {

    System.out.println(kingdom);
    System.out.println(lord);
    System.out.println(troop);
    System.out.println(troopAmount);
    System.out.println(weapon);
    System.out.println(animal);

}

how do I give troop class the arraylists without over writing them in the troop class?

  • 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-28T04:09:46+00:00Added an answer on May 28, 2026 at 4:09 am
    import java.util.ArrayList;
    import java.util.List;
    
    class Item {
        private name;
    
        public String getName() {
            return name;
        }
    
        private void setName(String name) {
            this.name = name;
        }
    
    
    public class ItemManager {
    
        public static List<ArrayList<Item>> megaList;
        public static void main(String args) {
    
            megaList = new ArrayList<ArrayList<Item>>();
    
            ArrayList<Item> someItems = new ArrayList<Item>();
            someItems.add(new Item());
            someItems.add(new Item());
    
            megaList.add(someItems);
    
            for(ArrayList<Item> list : megaList ) {
                for (Item item : list) {
                    String nameOfItem = item.getName();
                }
            }
        }
    

    Then you can iterate inside the megaList and recursively iterate inside the someItems.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.