title: ArrayList: IndexOutOfBounds exception issue
body: <p>I'm making a program to find prime numbers. I'm storing the prime numbers and all positive integers (right now till 100) in two <code>ArrayList&lt;Integer&gt;</code>. Here's the code:</p>
  
  <pre><code>import java.util.ArrayList;
  public class PrimeNumbers { 
  static ArrayList&lt;Integer&gt; num = new ArrayList&lt;Integer&gt;();
  static ArrayList&lt;Integer&gt; prime = new ArrayList&lt;Integer&gt;();
  public static void main(String[] args) {
      prime.add(2);
      prime.add(3);
      prime.add(5);
      for (int z = 1; z&lt;=100; z++){
          num.add(z);
      }
      outer: for (int a = 1; a &lt;=num.size(); a++){
          inner: for (int b = 1; b &lt;=prime.size(); b++){
              if (num.get(a)%prime.get(b) != 0){//line 14
                  if (prime.indexOf(b)+1 == prime.size()){
                      prime.add(a);
                      continue outer;
                  }
                  else 
                      continue inner;
              }
              else
                  continue outer;
          }
      }
      System.out.println(prime);
  
      }
  }
  </code></pre>
  
  <p>But when I run the program, these errors show up:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at PrimeNumbers.main(PrimeNumbers.java:14)</p>
  </blockquote>
  
  <p>What is going wrong?</p>