title: making a method to remove the zeros from an array in java
body: <p>was curious on how to write a method to remove all zeros from an array. If I have the array in the main method. for example my Main Method would look something like</p>
  
  <pre><code>  public static void main(String[] args) {
   int[] test = {1, 0, 4, 7, 0, 2, 10, 82, 0};
   System.out.println(Arrays.toString(test) +  ": length = " + test.length);
   int[] result = removeZeros(test);
   System.out.println(Arrays.toString(result) + ": length = " + result.length);
   }
  </code></pre>
  
  <p>and have the code output the length and the array without the zeros like: </p>
  
  <pre><code> [1, 0, 4, 7, 0, 2, 10, 82, 0]: length = 9
   [1, 4, 7, 2, 10, 82]: length = 6
  </code></pre>
  
  <p>I don't know how to write a method for this other than doing something like this:</p>
  
  <pre><code>  int[] test = {1, 0, 4, 7, 0, 2, 10, 82, 0};
      int length = 0;
      for (int i=0; i&lt;test.length; i++){
          if (test[i] != 0)
              length++;
      }
      int [] intResult = new int[length];
      for (int i=0, j=0; i&lt;test.length; i++){
          if (test[i] != 0) {
              intResult[j] = test[i];
              j++;
          }
      }
  </code></pre>
  
  <p>any ideas how to make this a method and have it print out both the original array and the new array without zeros in it + the length?</p>