adding objects to linkedlist/ arraylist in java -


i created storage class , use data type arraylist/linked list.

private linkedlist bid_history; 

i have initialised in constructure as

bid_history=new linkedlist <bid_history> (); 

i add new items list using add illustrated below

bid_history.add(new bid_history(bid_count,unit_price,bid_success)); 

after 'n' iterations checked contents of list , found out list has 'n' elements same. i.e. last element added occupied entire list. if added reference variable list?

any idea might have made mistake? used arraylist, same problem. guessing did wrong access specifiers! out of ideas.....

----added ------- use recursive function

bid() {    int bid,quantity;         bid_success=false;         bid_count++;         system.out.println("starting bid, bid id:"+bid_count);         quantity=(int)(rated_power*duration/60);         if(bid_history.isempty())         {             unit_price=10;         }         else         {             unit_price++;         }         bid=unit_price*quantity;         //sending calculated bid         send_res(unit_price,quantity,500);         long starttimems = system.currenttimemillis( );         system.out.println("time:"+starttimems);         while(!(system.currenttimemillis( )>(starttimems+2000)));         system.out.println("time @ end:"+system.currenttimemillis( ));          bid_history.add(new bid_history(bid_count,unit_price,bid_success));          if(bid_success!=true)         {             bid();         } } 

the printing code follows

int count=0,size; size=bid_history.size(); while(count<size) system.out.println(((bid_history)bid_history.get(count++)).getbid_amount()); 

another possibility bidhistory(count, price, success) not doing right job , not setting right fields. don't want guess, might instead of having fields in bidhistory using static count/price/success fields in class.

the constructor should ("this." important):

public bidhistory(int count, float price, boolean success) {     this.count = count;     this.price = price;     this.success = success; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -