title: what is difference between Array and ArrayList to get Prime numbers?
body: <p>i was solving problem about the prime numbers, i found solution using Arrays, but i wanted to use the array list for some issues, one of them is to understand the Arraylist  well. but i found that the results are not the same when i use the arraylist, here are the 2 Codes: </p>
  
  <p>//using Arrays</p>
  
  <pre><code>import java.util.Arrays;
  public class Prime {
      public static void main(String[] args) {
          primeNumber(100);
      }
      public static void primeNumber(int end) {
          boolean primeNumbers[] = new boolean[end]; 
          for (int i = 0; i &lt; end; i++) {
              primeNumbers[i] = true;
          }
          for (int i = 2; i &lt; primeNumbers.length; i++) {
              if (primeNumbers[i] ) {
                  for (int j = i+i; j &lt; primeNumbers.length; j += i) {
                      primeNumbers[j]= false;
                  }
              }
          }
          for (int j = 2; j &lt; primeNumbers.length; j++) {
              if (primeNumbers[j]) {
                  System.out.println(j);
  
              }
          }   
      }
  }
  </code></pre>
  
  <p>//Using ArrayList</p>
  
  <pre><code>import java.util.ArrayList;
  public class Prime {
      public static void main(String[] args) {
          primeNumber(100);
      }
  
      public static void primeNumber(int end) {
          ArrayList&lt;Boolean&gt; primeNumbers = new ArrayList&lt;Boolean&gt;(); 
          for (int i = 0; i &lt; end; i++) {
              primeNumbers.add(i,true);
          }
          for (int i = 2; i &lt; primeNumbers.size(); i++) {
              if (primeNumbers.get(i) ) {
                  for (int j = i+i; j &lt; primeNumbers.size(); j += i) {
                      primeNumbers.add(j, false);
                  }
              }
          }
          for (int j = 2; j &lt; primeNumbers.size(); j++) {
              if (primeNumbers.get(j)) {
                  System.out.println(j);
  
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Can i know what is the wrong i did with using the Arraylist, and if i wanted to use the arraylist for the same result what should i do. </p>
  
  <p>Great thanks for the help. </p>