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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:51:12+00:00 2026-06-05T22:51:12+00:00

I having trouble storing objects in an ArrayList . I want to populate an

  • 0

I having trouble storing objects in an ArrayList.

I want to populate an ArrayList with a simple object called Variable. It has 2 string attributes: name and value. The problem is when I add a new Variable object to the list, the attributes of the previously added Variable objects appear to be null. Also, instead of being added to the end of the list, the new object is inserted at the first position.

Here is the code :

ArrayList<Variable> variables = new ArrayList<Variable>();

Variable author = new Variable();
author.setName("Author");
author.setValue("lusyo"); 

variables.add(author);

System.out.println(variables.get(0).getName());

Variable scenario = new Variable();
author.setName("Scenario");
author.setValue("Login"); 

variables.add(scenario);

System.out.println(variables.get(0).getName());
System.out.println(variables.get(1).getName());

The output is :

Author
Scenario
null

As you can see, scenario is located at index 0, but it should not be. I can’t figure out what’s going on with this code.

Thank you in advance for your help !

  • 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-05T22:51:13+00:00Added an answer on June 5, 2026 at 10:51 pm
    Variable scenario = new Variable();
    author.setName("Scenario");
    author.setValue("Login");
    

    Does anything disturb you there? :)

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

Sidebar

Related Questions

I'm having some trouble adding an object to an arraylist. Basically the object has
I'm having some trouble with the logic behind storing an ImageView into an ArrayList.
I'm having trouble parsing Json string to Objects in C#. I'm using this: JavaScriptSerilizer
I'm having trouble converting objects into JSONObject (org.json.JSONObject) in java. I have an object
I'm having trouble figuring out how I can take a string of an object
I've made some new objects with object methods and I'm having trouble returning the
I'm having trouble understanding how to parse JSON string into c# objects with Visual
I'm having trouble storing and retrieving a float in NSUserDefauts. I store the value,
I'm having trouble looping through a set of dynamically created UITextFields and storing those
I am having a little trouble designing an efficient data storage method of storing

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.