java arraylist help needed -


have coded in many languages before new java. want create array members of type

public class data     {         string date="";         string time="";         double  price=0;         int volume=0;     };      data data1 = new data();     public arraylist ftsedata = new arraylist<data>(); 

i market data insert data1 followed by

ftsedata.add(data1); 

i wait fresh data , when insert again data1 , add ftsedata. although ftsedata seems increasing in size correctly seems elements of ftsedata pointers data1 , hence elements of ftsedata seems have values equal last data1 values.

i using arraylist because not know how many datapoint come in during day need expands.

could please tell me if should using arraylist or else , if arraylist problem.

many time.


many everyone,

i have 4 different functions each fill 1 part of data1. taking views on board, left data1 alone variable can seen in functions. in particular function adds data1 arraylist created datalocal variable of type data , copied datalocal.price= data1.price; etc etc added datalocal arraylist. seems work. assuming each time function called new local variable name datalocal created. , please let me know if there somethimng in way of doing things can me in trouble later,eg, other part of program write on 1 instance of datalocal because far program concerned need variable over.

yes, arraylist<e> (referred interface list<e>) looks data structure need in case.

the problem elements being references same object best solved making public class data immutable value type. whenever new data, instantiate new data object can put list.

see also

  • effective java 2nd edition, item 52: refer objects interfaces
  • effective java 2nd edition, item 15: minimize mutability

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -