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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:35:57+00:00 2026-06-03T19:35:57+00:00

I have a strange problem with arraylist. I add objects to arraylist in for

  • 0

I have a strange problem with arraylist. I add objects to arraylist in for loop, everything is working fine except arraylist add method. It seems like my list is adding each object twice but I can’t find a reason of this.
Here is my code

private void generateCitizens()
{
    int counter = Constants.CITIZENS_NUMBER;
    Random r = new Random(Calendar.getInstance().getTimeInMillis());
    while(counter > 0)
    {
        int x = r.nextInt(Constants.TILES_IN_WIDTH) + 1;
        int y = r.nextInt(Constants.TILES_IN_HEIGHT) + 1;

        if(map.collisionTable[y][x] == 2)
        {
            Citizen c = new Citizen(x, y, citizenTexture.deepCopy(), map);
            citizensList.add(c);
            Log.i("Citizens count", String.valueOf(citizensList.size()));
            scene.attachChild(c);
            counter--;
        }
    }

    for(int i = 0; i<citizensList.size(); i++)
    {
        Log.i("Citizen - ", citizensList.get(i).toString());
    }
}

Constants.CITIZENS_NUMBER is 15 in this case and this is what I got in logs

05-10 15:13:36.801: I/Citizens count(3237): 2
05-10 15:13:36.801: I/Citizens count(3237): 4
05-10 15:13:36.801: I/Citizens count(3237): 6
05-10 15:13:36.801: I/Citizens count(3237): 8
05-10 15:13:36.801: I/Citizens count(3237): 10
05-10 15:13:36.811: I/Citizens count(3237): 12
05-10 15:13:36.811: I/Citizens count(3237): 14
05-10 15:13:36.811: I/Citizens count(3237): 16
05-10 15:13:36.811: I/Citizens count(3237): 18
05-10 15:13:36.821: I/Citizens count(3237): 20
05-10 15:13:36.821: I/Citizens count(3237): 22
05-10 15:13:36.821: I/Citizens count(3237): 24
05-10 15:13:36.821: I/Citizens count(3237): 26
05-10 15:13:36.831: I/Citizens count(3237): 28
05-10 15:13:36.831: I/Citizens count(3237): 30
05-10 15:13:36.831: I/Citizen -(3237): com.lpp.towndefence.Citizen@40535d40
05-10 15:13:36.831: I/Citizen -(3237): com.lpp.towndefence.Citizen@40535d40
05-10 15:13:36.831: I/Citizen -(3237): com.lpp.towndefence.Citizen@40537318
05-10 15:13:36.831: I/Citizen -(3237): com.lpp.towndefence.Citizen@40537318
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@40514688
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@40514688
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@40799fe8
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@40799fe8
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079c308
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079c308
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079abd8
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079abd8
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079b4a0
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@4079b4a0
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba160
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba160
05-10 15:13:36.841: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba230
05-10 15:13:36.851: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba230
05-10 15:13:36.851: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba300
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba300
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba3d0
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba3d0
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba4a0
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407ba4a0
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bac18
05-10 15:13:36.861: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bac18
05-10 15:13:36.871: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bb3f0
05-10 15:13:36.871: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bb3f0
05-10 15:13:36.871: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bbc80
05-10 15:13:36.871: I/Citizen -(3237): com.lpp.towndefence.Citizen@407bbc80

  • 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-06-03T19:35:58+00:00Added an answer on June 3, 2026 at 7:35 pm

    Did you subclass the List class ?

    May new Citizen add itself to the list ? Or the attachChild method on scene ?

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

Sidebar

Related Questions

i have strange problem , my application (exe) is working fine in debug mode
I have strange problem when using at() method of std::string. I'd like to calculate
I have strange problem with run .exe program in my WebApplication. It works fine
I have strange problem. I have class which behaves similar dropdown list. package test.view;
Have a strange problem in that I have a Rake task that seems to
I have strange problem. When I use @return Model\Article in the model-loading method then
I have problem reading/println after the first two FOR loop in this method. This
i have strange problem doing reporting: i have numerous clients with different issued invoices.
I have strange problem with receiving data from socket. On client im using air
I have a strange problem with lxml when using the deployed version of my

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.