title: How to decrease the size of an array after removing some elements from it
body: <p>I'm working on a project and this is one of the task:
  create a method called "remove()" which can remove an element from an array.
  After removing it, if the number of elements are less than 1/4 of the array, the size of the array needs to decrease by half.</p>
  
  <p>For example:
  I have an size 100 array with 25 elements in it. After removing one element, I will have 24 elements, and the size of my array will be 50.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    //First create a method decrese
      private decrease() {
          if (numElement &lt; (1 / 4) * (Array.length)) {
          Array[] newarray = new Array[(Array.length) / 2];
          for (int i = 0; i &lt; numElement; i++)
              newarray[i] = Array[i];
          Array = newarray;   
      }
  
      //Then create my Remove method
      public void remove(ToRemove){
      if (numElement &gt; 0) {                //First check if my array is empty
          for (int i = 0; i &lt; numElement; i++) {
              if (Array[i].equals(ToRemove)) {
                  Array[i] = Array[numElement - 1];
                  Array[numElement - 1] = null;
                  numElement--;
                  decrease();
              }
          } 
       //if the Array is empty, also decrease the size 
       decrease();
       }
  </code></pre>
  
  <p>After some test run, my remove works fine,the Array length would never decrese no matter what size I put in.</p>
  
  <p>Can some one help me.
  Thanks</p>