title: IndexOutOfBoundsException: I don't see in my while loop
body: <p>Ive been stuck on this <code>IndexOutOfBoundsException</code> that I can't figure out and I don't see why it's pointing to my <code>while</code> loop. Any suggestions on what to do? The method btw is a round robin scheduling simulator, it seems to be working perfectly with one of my testfiles but not the other.</p>
  
  <pre><code>public void roundRobin2(ArrayList&lt;Jobs&gt; c, int startSize)
  {   
      //int n = 0;
      double counter = 0;
      double compTime = 0;
      while(!c.isEmpty())
      {
          int i = 0;
          System.out.println(c);
          for(i = 0; i &lt; c.size(); i++)
          {
              if((c.get(i).jobTime) &gt;= 2)
              {
                  c.get(i).jobTime -= 2;
                  counter += 2;
  
                  if((c.get(i).jobTime) == 0)
                  {
                      compTime += counter;
                  }
              }
              else
              {
                  (c.get(i).jobTime) -= 1;        
                  counter += 1;
  
                  if((c.get(i).jobTime) == 0)
                  {
                      compTime += counter;
                  }
              }
              //System.out.print("-" + c.get(i).jobName + "-" + counter);
              //n++;
              //if(n%10 == 0)
              //{
                  //System.out.println("\n");
              //}
          }
          for(i = 0; i &lt; c.size(); i++)
          {
              while(!c.isEmpty() &amp;&amp; (c.get(i).jobTime) == 0)
              {
                  c.remove(i);
              }       
          }
      }
      System.out.println("\n\nAverage completion times: "+ compTime + "/" + startSize +" = " + ((compTime)/startSize));
  }
  </code></pre>
  
  <p>The exception stacktrace:</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
      at java.util.ArrayList.rangeCheck(Unknown Source)
      at java.util.ArrayList.get(Unknown Source)
      at cs431.edu.cpp.Main.roundRobin2(Main.java:143)
  </code></pre>