title: JAVA Dynamic Array
body: <p>I will post my code and hope someone can tell what to change to make a "dynamic array"? The current code works but they told me it is not the correct way and instead of this I need to make a dynamic array. Thanks in advance.</p>
  
  <pre><code>public static void main(String[] args) {
  
  int i,a,b;
  int [] array1 = new int[20];//{12,23, -22, 0, 43,545, -4, -55,43, 12,0, -999, -87
  
  array1[0] = 12;
  array1[1] = 23;
  array1[2] = -22;
  array1[3] = 0;
  array1[4] = 43;
  array1[5] = 545;
  array1[6] = -4;
  array1[7] = -55;
  array1[8] = 43;
  array1[9] = 12;
  array1[10] = 0;
  array1[11] = -999;
  array1[12] = -87;
  
  int [] arrayPlus = new int[20];
  int [] arrayMinus = new int[20];
  
  
  a=b=0;
  
  
  for (i = 0; i &lt; 13; i++) {
      if (array1[i] &gt; 0 || array1[i] == 0) {
          arrayPlus[a] = array1[i];
          a++;
      } else {
          arrayMinus[b] = array1[i];
          b++;
      }
  }
  System.out.println("Positive array numbers");
  for (i = 0; i &lt; a; i++) {
  System.out.println(arrayPlus[i]);}
  
  
  System.out.println("");
  
  System.out.println("Negative array numbers");
  for (i = 0; i &lt; b; i++) {
  System.out.println(arrayMinus[i]);}
  
  }
  }
  </code></pre>