title: Please share your thoughts on how to improve the below program. New coder wanting to learn how to better compuitational thinking
body: <p>I wanted to create a program that lists all prime numbers to a given upper bound and that will provide the amount of primes in the set. After many hours of trial and error I was able to solve it.</p>
  <p>I am sure this is not efficient and I want to learn how to look at code and see where improvements can be made. Or just to simply improve my computational thinking.</p>
  <p>For instance, would it be better to not put this in an ArrayList?</p>
  <p>Thanks in advance.</p>
  <pre><code>
  //Program should be able to print all primes between 1 and a given number and should also provide the amount of primes for the given set. 
  
  public class NewPrimes {
      
      //Method to loop a value and to determine if the number is a prime. 
      public static void primes (int upperBound) {
          ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;();
          
          for (int i = 2; i &lt;= upperBound; i++) {
              if (i == 2) {
                  arr.add(2);
              }
              for (int x = 2;(x &lt; i) &amp;&amp; (i % x != 0); x++) {
                  if (x == i - 1) {
                      arr.add(i);
                  }
              }
          }
          System.out.println(arr);
          System.out.println(arr.size());
          
      }
      
  
      public static void main(String[] args) {
          NewPrimes.primes(1000);
          NewPrimes.primes(100);
          NewPrimes.primes(10000);        
      }
  } ```
  </code></pre>