title: Java - IndexOutOfBoundsException: Index: 1, Size: 0
body: <pre><code>public static boolean play123(ArrayList&lt;Card&gt;list){
      boolean win=false;
      int round=1;
      for(int i = 0;i&lt;=list.size();i++){
          Deck.handOutNextCard(list);     
          if(list.get(i)==Card.AceClub ||list.get(i)== Card.AceDiamond ||list.get(i)== Card.AceHeart ||list.get(i)== Card.AceSpade){
              if(round==1){
              System.out.println("You loose! " +list.get(i)+"From round: "+round); 
              i = list.size()+1;
              win = false;
              }
          }
          else if(list.get(i)==Card.TwoClub ||list.get(i)== Card.TwoDiamond ||list.get(i)== Card.TwoHeart ||list.get(i)== Card.TwoSpade){
              if(round==2){
              System.out.println("You loose! " + list.get(i)+"From round: " +round);
              i = list.size()+1;
              win = false;
              }
          }else if(list.get(i)==Card.ThreeClub ||list.get(i)== Card.ThreeDiamond ||list.get(i)== Card.ThreeHeart ||list.get(i)== Card.ThreeSpade){
              if(round==3){
              System.out.println("You loose! " + list.get(i)+"From round: " +round);
              i = list.size()+1;
              win=false;
              }
          }else{
              if(round&lt;3){
                  list.remove(0);
                  i=0;
                  round++;
              }else{
                  list.remove(0);
                  i=0;
                  round=1;
              }
          }
          if(list.isEmpty()){
              System.out.println("You win ! ");
              win = true;
          }
      }
      return win;
  }
  </code></pre>
  
  <p>I got sometimes IndexOutOfBoundsException: Index: 1, Size: 0 error when using the method for example about 100 times, what could be the problem ://
  I have tried to fix it through using different loop types but it was not possible, and the index and the size are different sometimes, and this is the handOutNextCard(list) method:
  public static Card handOutNextCard(ArrayListlist){</p>
  
  <pre><code>    Card current = list.get(0);
      list.remove(0);
      return current;
  
  }
  </code></pre>