In this code i need an object to be removed if a certain value is zero [Portfolio.total.get(k).get(c).current_quantity==0].
for(int k=0;k<Run_process.total_Agents;k++){
for(int c=0;c<Portfolio.total.get(k).size();c++){
if(Portfolio.total.get(k).get(c).current_quantity==0){
System.out.println("delete Agent"+k+" "+Portfolio.total.get(k).get(c).stocks.stock_Id);
Portfolio.total.get(k).remove(c);
//remove from portfolio if there is no quantity
}
}
//Portfolio.total.get(k).trimToSize();
}
//Portfolio.total.trimToSize();
for(int k=0;k<Run_process.total_Agents;k++){
for(int c=0;c<Portfolio.total.get(k).size();c++){
if(Portfolio.total.get(k).get(c).current_quantity==0){
System.out.println("still zero quantity Agent"+k+" "+Portfolio.total.get(k).get(c).stocks.stock_Id);
//remove from portfolio if there is no quantity
}
}
//Portfolio.total.get(k).trimToSize();
}
The problem is that after i run this loop again to check if everything is ok BUT sometimes seems that 1-3 values although have [Portfolio.total.get(k).get(c).current_quantity==0] are still in the arraylist.The next time this code runs this object is properly deleted. To sum up some values are deleted the next time this code runs