for(int i=0;i<Stockhouse.total_stocks;i++){
buyers.clear();
for(int j=0; j<buy.size();j++){
if(buy.get(j).stock_Id.equals("Stock"+i)){
System.out.println("Agent "+buy.get(j).ID+",stock"+buy.get(j).stock_Id+",price "+buy.get(j).price +",quant "+buy.get(j).quantity);
Auctionhouse buypr= new Auctionhouse(buy.get(j).price,buy.get(j).quantity);
buyers.add(buypr);
}
}
total_buy.add(buyers);
System.out.println("buy size "+total_buy.get(i).size());
}
here the buy size shows me correctly the size of each ArrayList as an elements of total_buy ArrayList.
My problem is that after when i need these sizes again,i only get the size of the last ArrayList.
total_buy.get(0).size()=3
total_buy.get(1).size()=3
total_buy.get(2).size()=3.......
but only total_buy.get(2).size()=3 is actually 3!