text: Q:
  
  Not removing object from ArrayList
  
  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
  
  A:
  
  When you remove something, all following indexes decrease by 1. Incrementing your loop counter  will skip the next element. They are the ones you are missing.
  You need to do something like this:
  Portfolio.total.get(k).remove(c); // you already have this line
  c--;
  
  Also, for the sake of readability I would prefer to use an Iterator and it's remove() method. This way you don't have to worry about indexes.
  
  