在此代码中,如果某个值为零 [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();
}
问题是,在我再次运行此循环以检查一切是否正常但有时似乎 1-3 个值虽然 [Portfolio.total.get(k).get(c).current_quantity==0] 仍在arraylist。下次运行此代码时,此对象将被正确删除。总而言之,下次运行此代码时会删除一些值