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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:20:39+00:00 2026-05-14T00:20:39+00:00

I am adding elements to a ArrayList and it adds the first one correctly

  • 0

I am adding elements to a ArrayList and it adds the first one correctly but then when I add any subsequent elements it wipes replaces the other elements with the value from the most recently added and adds a new element to the ArrayList.

I ran test using arraylist and ints and even another created class and it worked perfectly but something about the custom class I am using here causes problems.

The code for the array list is

public static void main(String args[]){
   List<BasicEvent> list = new ArrayList<BasicEvent>();
   list.add(new BasicEvent("Basic", "Door", 9, 4444, new Date(12,04,2010), new Time(12,04,21), 1, 0.98, 0));
   list.add(new BasicEvent("Composite", "Door", 125, 4444, new Date(12,04,2010), new Time(12,04,20), 1, 0.98, 1));
   list.add(new BasicEvent("Basic", "Door", 105, 88, new Date(12,04,2010), new Time(12,05,23), 1, 0.98, 0));
   list.add(new BasicEvent("Basic", "Door", 125, 12, new Date(12,04,2010), new Time(12,05,28), 1, 0.98, 1));
   list.add(new BasicEvent("Basic", "Door", 129, 25, new Date(12,04,2010), new Time(12,05,30), 1, 0.98, 0));
   list.add(new BasicEvent("Basic", "Door", 125, 63, new Date(12,04,2010), new Time(12,04,20), 1, 0.98, 1));
   list.add(new BasicEvent("Basic", "Detect", 127, 9, new Date(12,04,2010), new Time(12,05,29), 1, 0.98, -1));

   for(int i=0;i<list.size();i++) {System.out.println("list a poition " + i + " is " + BasicEvent.basicToString(list.get(i)));}

And the code for the custom class basicEvent is

public class BasicEvent {
  public static String Level;
  public static String EType;
  public static double xPos;
  public static double yPos;
  public static Date date;
  public static Time time;
  public static double Rlb;
  public static double Sig;
  public static int Reserved;

  public  BasicEvent(String L, String E, double X, double Y, Date D, Time T, double R, double S, int Res){
   Level = L;
   EType = E;
   xPos = X;
   yPos = Y;
   date = D;
   time = T;
   Rlb = R;
   Sig = S;
   Reserved = Res;
  };

 public static String basicToString(BasicEvent bse){
   String out = bse.getLevel() + ";" + bse.getEtype() + ";" + bse.getxPos() + ";" + bse.getyPos() + ";" + bse.getDate().dateAsString() + ";" + bse.getTime().timeAsString() + ";" + bse.getRlb() + ";" + bse.getSig() + ";" + bse.getReserved();
   return out;
  }
  • 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-14T00:20:40+00:00Added an answer on May 14, 2026 at 12:20 am

    All the members of your class BasicEvent are static, i.e. they are shared between all instances of the class. Thus when you create a new instance, the properties of the old instance are overridden with the new values.

    You should change your class definition to

    public class BasicEvent {
      public String Level;
      public String EType;
      public double xPos;
      public double yPos;
      public Date date;
      public Time time;
      public double Rlb;
      public double Sig;
      public int Reserved;
      ...
    }
    

    As a side note, in general it is not good practice to use public fields – better make them private and provide public accessors / setters only as needed. Of course, in experimental code it does not matter much, but in production quality code it does.

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

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer split does include empty matches in the result, have a… May 16, 2026 at 11:12 pm
  • Editorial Team
    Editorial Team added an answer There's a standalone gnureadline package available, you can install it… May 16, 2026 at 11:12 pm
  • Editorial Team
    Editorial Team added an answer You need to } with }); before $.getJSON('http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=' + appid… May 16, 2026 at 11:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm doing a simple program using arraylist. But I've encountered an error. After deleting
I'm having trouble getting the right number of elements in the ArrayList alt in
I've a bit of a problem. I'm adding numbers to ArrayList like 156, 340
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
I'm trying to display dynamically changeable data manipulating with DOM elements (adding/removing them). I
I have DOM elements I'd like to exclude from a .click function by adding
I have two collections - an ArrayList and a Stack. I use the stack
I have an array of any type T ( T[] ) and I want
I have a List object being accessed by multiple threads. There is mostly one
I'm adding an element to a document with the following: Element parent = getParentElement();

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.