title: How to pass result from an array to another method without 0 numbers in java?
body: <p>Can you please advise how can I pass results from an array to another array without some numbers? In this case without zero numbers. Here is my code, I'm stuck.</p>
  
  <p>Result is: [0, 1, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11] - all I want to do, is to create another array and pass there numbers from above without 0's.</p>
  
  <p>Thanks.</p>
  
  <pre><code>public class SieveOfEratosthenes {
      public static void main(String[] args) {
          int[] myArray = new int[12];
  
          fillArrayWithNumbers(myArray);
  
          System.out.println(Arrays.toString(sieve(myArray)));
  
      }
  
      private static void fillArrayWithNumbers(int[] myArray) {
          for (int i = 0; i &lt; myArray.length; i++) {
              myArray[i] = i;
          }
      }
  
      public static int[] sieve(int[] maximumNumber) {
          for (int j = 2; j &lt; maximumNumber.length; j++) {
              for (int i = j * 2; i &lt; maximumNumber.length; i += j) {
                  maximumNumber[i] = 0;
                  }
          }
          return maximumNumber;
      }
  }
  </code></pre>