title: Removal of negative numbers from an array in Java
body: <p>My objective is to remove all negative numbers from an array in Java.</p>
  
  <p>I have written the below code. How do I improve the complexity of code or is there a good algorithm?</p>
  
  <pre><code>public static void main(String[] args) {
      int[] array = { 1, -3, 4, -9, 3, 4, 70, -10, 0, 7 };
      System.out.println(Arrays.toString(removeNegativeNumbers(array)));
  }
  
  public static int[] removeNegativeNumbers(int[] num) {
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      for (int n : num) {
          if (n &gt;= 0) {
              list.add(n);
          }
      }
      int[] result = new int[list.size()];
      for (int i = 0; i &lt; result.length; i++) {
          result[i] = list.get(i).intValue();
      }
      return result;
  }
  </code></pre>