title: Using ArrayDeque Java
body: <p>I'm trying to store a list of primes using java and came across ArrayDeque. I'm not sure if this is the correct occasion to use it, but since I don't know the number of primes I need the capacity to grow. </p>
  
  <p>The code is designed to go through numbers 2 to 1000 and test if they are a prime or not.</p>
  
  <p>I'm getting some errors. I am pretty new to this so if anybody could guide me in the right direction that would be great. Is using a Array with a large pre-set capacity a better way of doing things? </p>
  
  <p>Many thanks,
  Behzad</p>
  
  <pre><code>import java.util.ArrayDeque;
  import java.util.Deque;
  
  public class Maths {
  public static void main (String[] arg) {        
  
      int x = 2;
      ArrayDeque&lt;integer&gt; primes = new ArrayDeque&lt;integer&gt;(8);
  
      for(int count = 2; count&lt;1000; count++) {
          if (x%count == 0) {
              System.out.println("Number is not prime"); // If it isn't a prime, it moves onto the next number.
              x = x + 1;
              count = 2;
          }
  
          else if (x &gt;1000) {
              break;
          }
  
          else if (count == x - 1) {
              System.out.println( x + " is a prime"); //This possibility singles out prime numbers
              primes.add(x);
              x = x + 1;                              // Need to find a way to add them to memory.
              count = 2;
          }
      }
      System.out.println("Searchfinished");
      System.out.println(primes);
  }
  }
  </code></pre>