title: How to find prime numbers by using an ArrayList in java
body: <p>I was working with coding in java and I am stuck in this code which I implemented for finding prime numbers .</p>
  
  <pre><code>public class PrimeList {
  
      ArrayList&lt;Integer&gt; list;
  
      public PrimeList(int n){
  
          list = new ArrayList&lt;Integer&gt;();
  
          preparePrimeList(n);
      }
  
      private void preparePrimeList(int n){
          int c =0;
          for (int i=0; i&lt;=n; i++) {
  
              if (i%2!=0 &amp;&amp; i%3!=0 &amp;&amp; i%5!=0 &amp;&amp; i%7!=0) {
                  list.add(i);
                  c++;
              }
          }
  
          list.remove(0);
          list.remove(1);
      }
      public void printPrimeList(){
          System.out.println(list);
      }
      public boolean isPrime(int nbr){
  
              if (list.contains(nbr)) {
                  return true;
          }
          return false;
      }
  
  
      public static void main(String[] args) {
  
          PrimeList primes = new PrimeList(100);
          primes.printPrimeList();
          primes.isPrime(33);
  
      }
  
  }
  </code></pre>
  
  <p>When I run the code I get the following : </p>
  
  <pre><code>[11, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
  </code></pre>
  
  <p>Why I get wrong output ? the out put should be like this : </p>
  
  <pre><code>2, 3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
  83, 89, 97
  false
  </code></pre>
  
  <p>What I am doing wrong ?</p>
  
  <p>Thank you</p>